I'm implementing search functionality into my application. The search results in the UI are returned based on an array of objects. Essentially what I'm trying to do is iterate over the name, custNumber, and sneak values in each object, and only return the objects that contain a value that includes a string (generated from the users search bar). The idea is that users can search for anything in the object and yield the correct results
here is my array
var result = [{
name: 'Donna Shomaker',
custNumber: '6658924351',
sneak: 'string1 string1 string1',
foo: false,
bar: false,
},
{
name: 'Ron Duluth',
custNumber: '8812654434',
sneak: 'string2 string2 string2',
foo: false,
bar: false,
},
{
name: 'Jimmy Dawson',
custNumber: '8908198230',
sneak: 'string3 string3 string3',
foo: false,
bar: false,
}
]
This is how far I've gotten
return result.filter(convo => {
return convo.name.toLowerCase().includes(searchbarVal.toLowerCase())
})
The obvious problem here is that this only is only returning objects based on the name value. However, I need it to compare the name, custNumber, and sneak values in each object to the users search. I've tried forEach, object.values, and object.entries methods and haven't been able to get them to work. Any help here is much appreciated!!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…