javascript - In an array of objects, returns objects where ANY value matches a specific string

后端 未结 5 946
清酒与你
清酒与你 2020-12-04 00:56

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 ite

5条回答
  •  再見小時候
    2020-12-04 01:17

    A 'some' in your filter might do the trick, checking all the keys.

    return result.filter(convo => {
      return Object.keys(convo).some(key => {
         return convo[key].toLowerCase().includes(searchbarVal.toLowerCase())
      })
    })
    

提交回复
热议问题