JSFiddle - React, Tailwind, and code Playground
by Terry Mun
JavaScript
var query = "Define what is grape juice and how to drink it?",
terms = ["define", "what is", "how to"],
matchedTerms = [];
$.each(terms, function(i,v) {
var match = query.indexOf(v);
matchedTerms.push({
'term': v,
'index': match
});
});
console.log(matchedTerms);