【发布时间】:2018-11-06 15:25:29
【问题描述】:
我有一系列结果。我想将结果过滤到一个数组,其categorys 至少有一个对象的cat_id 或1。我该怎么做?
"results": [
{
"product_id": 1,
"title": "booking",
"draft": false,
"publish": true,
"category": [
{
"cat_id": 1,
"cat_name": "web",
"product": "booking"
}
],
},
{
"product_id": 2,
"title": "reading",
"draft": false,
"publish": true,
"category": [
{
"cat_id": 6,
"cat_name": "android",
"product": "asdasd"
}
],
},
{
"product_id": 3,
"title": "reading",
"draft": false,
"publish": true,
"category": [],
},
]
我的尝试:
for (let i = 0; i < data.results.length; i++) {
this.webCatProducts = data.results[i].category.filter(d => d.cat_id == 1)
console.log(this.webCatProducts)
}
【问题讨论】:
-
是的,它可以是空的,也可以有 3 个您可以在上面看到的对象
标签: javascript arrays json typescript ecmascript-6