[英]node.js find attributes with same value in multiple JSON files
嘿,我想问一下是否可以在 10 个 JSON 文件中找到这样的文件:
1.json:
{
"name": "Miami",
"attributes": [
{
"att_type": "People",
"value": "1000"
},
{
"att_type": "Cars",
"value": 300
}
]
}
2.json:
{
"name": "New York",
"attributes": [
{
"att_type": "People",
"value": "5000"
},
{
"att_type": "Cars",
"value": 900
}
]
}
等等...只是不同的属性值。 可以说我只想找到人员> 2500 的城镇,我什至不确定是否可能,或者我是否需要将 json 文件上传到某个数据库?
谢谢你。
const data = [{ "name": "Miami", "attributes": [{ "att_type": "People", "value": "1000" }, { "att_type": "Cars", "value": 300 } ] }, { "name": "New York", "attributes": [{ "att_type": "People", "value": "5000" }, { "att_type": "Cars", "value": 900 } ] } ] const result = data // find cities with attribute `People` with value greater than 2500.filter(d => +d.attributes.find(attr => attr.att_type === 'People').value > 2500) // get name of the city.map(d => d.name) console.log(result)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.