How do i filter an array inside of a array of objects?

前端 未结 4 844
暗喜
暗喜 2021-02-04 17:58

I\'m trying to filter a list by tags:

const initialState = [
     {id:1 ,name: \'Product A\', image: \'pic-001.jpg\', tags: [\'nature\', \'campi         


        
4条回答
  •  鱼传尺愫
    2021-02-04 18:14

    you can use indexOf function

    var foo = initialState.filter(function(elm){
      return elm.tags.indexOf("camping")>=0
    });
    

提交回复
热议问题