I need to filter a JSON like this:
{
"suggestions":[
"futebol brasileiro",
"futebol americano",
"futebol",
"musica",
"musicas",
"musica inedita de raul",
"politica entre dilma e aecio",
"politica",
"politica macroeconomica"
]
}
When I type "pol" in a input field, I need to get this JSON:
{
"suggestions":[
"politica entre dilma e aecio",
"politica",
"politica macroeconomica"
]
}
How can I do that using pure Javascript?
I did that in JQuery:
var url = "/busca/suggests/?q="+query;
$.getJSON(url, function (data) {
for(var i=0; i < data.length; i++) {
people[i] = accent_fold(data[i]);
}
});
//Case insensitive search for our people array
var results = $.grep(people, function(item){
return item.search(RegExp(query, "i")) != -1;
});
If you can use ECMAScript 5...
Otherwise: Polyfill for
Array.prototype.filter()