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")
}
}))
添加回答
举报