2 回答

TA貢獻1712條經驗 獲得超3個贊
您可以使用Array.prototype.map遍歷數組的每個元素,然后使用fakeData過濾子數組并從每次迭代的調用中返回一個新對象Attributes.projexArray.prototype.filtermap
調用中的新對象Array.prototype.map是通過使用對象擴展運算符獲取每個元素的所有屬性(屬性除外) ,然后將新數組從分配給每個新對象:fakeData...Attributes.projexAttributes.projexArray.prototype.filter
const fakeData = [ { Id: "022173333101", Name: "Blue", System: "DESIGN", Squares: 0, Attributes: { projex: [ { Project: "50", HeightPay: "1" }, { Project: "50", HeightPay: "0" } ] }, Customer: { Addr1: "Somewhere", Addr2: "" } } ];
const found = fakeData.map(data => ({
...data,
Attributes: {
projex: data.Attributes.projex.filter(({
HeightPay
}) => HeightPay === "1")
}
}));
console.log(found);

TA貢獻1865條經驗 獲得超7個贊
const result = fakeData.map(item => ({
...item,
Attributes: {
projex: item.Attributes.projex.filter(e => e.HeightPay === "1")
}
}))
添加回答
舉報