Filtering array of objects by searching nested object properties

后端 未结 6 716
执笔经年
执笔经年 2020-12-06 07:38

I have an array of objects that I want to filter by comparing a nested property to a search term.

For example:

 var array = [
      {category: \'Bus         


        
6条回答
  •  星月不相逢
    2020-12-06 08:11

    You can use array.filter like this:

    function getFiltered(val) {
         return array.filter(category == val);
    }
    

    This function will return a new array instance, only with the category keys you passed as the val params.

提交回复
热议问题