I am trying to search with the word from the list of objects available in an array and it is available in all the objects then i should print a message as "Matched"
var objects = [
{
"foo" : "shaik",
"bar" : "sit"
},
{
"foo" : "lorem",
"bar" : "ipsum"
},
{
"foo" : "dolor",
"bar" : "shaik"
}
];
var results = [];
var toSearch = "shaik";
for(var i=0; i<objects.length; i++) {
for(key in objects[i]) {
if(objects[i][key].indexOf(toSearch)!=-1) {
results.push(objects[i]);
}
}
}
gs.log(JSON.stringify(results));
Output:
*** Script: [{"foo":"shaik","bar":"sit"},{"foo":"dolor","bar":"shaik"}]
As of now with the above script i am able to display the matched objects but how to check like if it is available in all the objects then display Matched as result