I have an array of objects lets say:
var ob=[
{
name:'john',
surname:'fox'
}, {
name:'jill',
surname:'hog'
}
];
I'm implementing search on a website, where i can input either name or surname, and it should filter new array by objects that contain input value.
So if my input is 'fox' it will filter out the object that contains key value 'fox'
my simple idea was :
ob.filter(item=>{ return item.name.includes(searchterm) ||
item.surname.includes(searchterm)}
But i guess there are better ways, in case key names change.