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

前端 未结 4 845
暗喜
暗喜 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:30

    Like that?

    const filter = 'nature';
    const filteredResult = initialState.filter((item) => {
        return (item.tags.indexOf(filter) >= 0);
    });
    

提交回复
热议问题