2 回答

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以使用 find() 或 filter() 方法。
var postdata = [{name: "somekey1", value:"somevalue1"},{name: "somekey2", value:"somevalue2"}];
let findObject = postdata.find(e => e.name == 'somekey1');
let filterObject = postdata.filter(e => e.name == 'somekey1');
console.log(findObject);
console.log(filterObject);

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊
也許你可以使用下面的代碼;
let result = Object.fromEntries(
// convert to array, map, and then fromEntries gives back the object
Object.entries(postdata).map(([key, value]) => {
//Some condition..
})
);
添加回答
舉報(bào)