2 回答
TA贡献1802条经验 获得超5个赞
这可以使用 来完成Array.prototype.flatMap。
const unitsAndRates = [
{
propertyUnitType: "store",
propertyUnitRate: "20000",
numberOfUnit: 4
},
{
propertyUnitType: "duplex",
propertyUnitRate: "20000",
numberOfUnit: 3
}
];
const result = unitsAndRates.flatMap((item) => [...Array(item.numberOfUnit).keys()].map((index) => ({
propertyUnitType: item.propertyUnitType + (index + 1),
propertyUnitRate: item.propertyUnitRate
})));
console.log(result);
TA贡献1842条经验 获得超12个赞
unitsAndRates.map(item => ({
propertyUnitType: item.propertyUnitType,
propertyUnitRate: item.propertyUnitRate
}))
或者
unitsAndRates.map({propertyUnitType, propertyUnitRate} => ({propertyUnitType, propertyUnitRate }))
如果您需要按提交的numberOfUnit进行过滤,请尝试:
const filteredUnits = unitsAndRates.filter(item => item.numberOfUnit === "2000")
然后你可以做映射
filteredUnits.map({propertyUnitType, propertyUnitRate} => ({propertyUnitType, propertyUnitRate }))
添加回答
举报