I have the following object "list":
{
...
2: {id: 35, name: 'dog Sharik'},
3: {id: 36, name: 'cat Murzik'}
...
}
Need to find object which consist 'cat' word in name. What is the best way to do it (does Jquery can help with it?)
I have the following object "list":
{
...
2: {id: 35, name: 'dog Sharik'},
3: {id: 36, name: 'cat Murzik'}
...
}
Need to find object which consist 'cat' word in name. What is the best way to do it (does Jquery can help with it?)
Iterate the loop and find it.Use a for loop to iterate the obj and return when the name property of the object contains the word cat.Here obj is your original object
CODE
function findmatching(obj,word){
for(var key in obj){
if(obj[key]['name'].indexOf(word)!=-1){
return obj[key]
}
}
}
var mymatchingvalue=findmatching(userinput,word)
You can use lodash/underscore.js
_.filter(list, function(d) { return _.includes(d.name, 'cat') })