JavaScript
var jsObjects = [
{
"id": "01",
"value": "01"
},
{
"id": "02",
"value": "02"
},
{
"id": "03",
"value": "03"
},
{
"id": "03",
"value": "04"
},
{
"id": "05",
"value": "05"
}
];
var result = jsObjects.filter(x => x.id === '03');
参考:https://stackoverflow.com/a/35398031/7151777
Python3
py_dicts = [
{
"id": "01",
"value": "01"
},
{
"id": "02",
"value": "02"
},
{
"id": "03",
"value": "03"
},
{
"id": "03",
"value": "04"
},
{
"id": "05",
"value": "05"
}
]
result = list(filter(lambda x: x['id'] == '03', py_dicts))
如果仅仅想判断是否存在, 则可以使用find
let arr = [
{ name:"string 1", value:"this", other: "that" },
{ name:"string 1", value:"this", other: "that" },
{ name:"string 2", value:"this", other: "that" }
];
let obj = arr.find(o => o.name === 'string 1');
console.log(obj);
参考:
https://stackoverflow.com/a/12462414
https://stackoverflow.com/a/25373204/7151777