我在json中有数据,想要在node.js中过滤数据。 json中的数据粘贴在下面我想只显示那些set_account:false的数据。
{"menu": {
"header": "SVG Viewer",
"items": [
{"name":"idea"},
{"set_account":"false"},
{"id": "Open"},
{"id": "OpenNew", "label": "Open New"},
null,
{"name":"idea"},
{"id": "ZoomIn", "label": "Zoom In"},
{"id": "ZoomOut", "label": "Zoom Out"},
{"id": "OriginalView", "label": "Original View"},
null,
{"name":"airtel"},
{"set_account":"false"},
{"id": "Quality"},
{"id": "Pause"},
{"id": "Mute"},
null,
{"name":"vodafone"},
{"id": "Find", "label": "Find..."},
{"id": "FindAgain", "label": "Find Again"},
{"id": "Copy"},
{"id": "CopyAgain", "label": "Copy Again"},
{"id": "CopySVG", "label": "Copy SVG"},
{"id": "ViewSVG", "label": "View SVG"},
{"id": "ViewSource", "label": "View Source"},
{"id": "SaveAs", "label": "Save As"},
null,
{"name":"jio"},
{"id": "Help"},
{"id": "About", "label": "About Adobe CVG Viewer..."}
]
}}
答案 0 :(得分:0)
使用array.filter:
var inventory = [{
name: 'apples',
quantity: 2
}, {
name: 'bananas',
quantity: 0
}, {
name: 'cherries',
quantity: 5
}, {
name: 'cherries',
quantity: 8
}];
function findCherries(fruit) {
return fruit.name === 'cherries';
}
console.log(inventory.filter(findCherries));