抱歉,伙计们,但我有一个假的问题..我需要从json响应中迭代对象,并仅获取那些满足某些条件的对象..响应是这样的: result = [ { "type": "EVENT", "id": "001", "tags": [ { "id": "98765", "name": "home" } ] }, { "type": "EVENT", "id": "002", "tags": [ { "id": "7654", "name": "contact" } ] }, { "type": "EVENT", "id": "003", "tags": [] } ]我只需要使用那些类型为'event'且标签中的name属性为home的属性。我尝试过地图和过滤器,但没有得到理想的结果const eventType = result.filter(type => type.type == 'EVENT') const nameFilter = eventType.map(item => item.tags) .filter(sub => sub.length) // remove empty [] .map(subarray => subarray.map(element => element.name ) .filter(element => element == 'home')); 结果: [ ['home'], // dosen t work for me, because need all the object [], [] ]
添加回答
举报
0/150
提交
取消