【发布时间】:2020-08-04 00:02:20
【问题描述】:
我正在尝试组合 3 个对象数组,同时保持原始数组的相同索引。我可以通过使用spread operator 方法来实现这一点。我目前的问题是,由于它的兼容性,我在 Internet Explorer 上遇到了问题。如果不使用spread operator 方法,我一直无法找到另一种方法。这是否可以通过与 Internet Explorer 兼容的方法来完成?
这是我正在使用的当前代码:
const revenueArr = [{title: 'online', revenue: 34321, revenueGrowth: 3.2},{title: 'retail', revenue: 321, revenueGrowth: 1.2} ]
const employArr = [ { employGrowth: 0.2 }, {employGrowth: -1.2} ]
const businessArr = [ {businessGrowth: 2.8}, {businessGrowth: 1.6} ]
const allData = revenueArr.map((it, index) => {
return { ...it, ...employArr[index], ...businessArr[index]}
})
console.log(allData)
我的预期结果是上面代码 sn-p 中的 console.log,其中对象的第一个索引在将它们组合在一起后仍然是第一个索引。如:
[
{
"title": "online",
"revenue": 34321,
"revenueGrowth": 3.2,
"employGrowth": 0.2,
"businessGrowth": 2.8
},
{
"title": "retail",
"revenue": 321,
"revenueGrowth": 1.2,
"employGrowth": -1.2,
"businessGrowth": 1.6
}
]
【问题讨论】:
标签: javascript arrays cross-browser