在数组中合并数组

时间:2019-05-31 18:47:21

标签: javascript arrays reactjs sorting object

我有一个包含另外2个对象数组的数组,我想将其变成单个对象数组。我已经发布了当前的代码和想要的结果

我尝试了concat方法,但可能实现错误?

var code = [
  [{Adults:"1", Price: "14.50"}],
  [{Adults:"1", Price: "20.50"}]
]

var result = [
  {Adults: "1", Price: "14.50" },
  {Adults: "1", Price: "20.50"}
]

1 个答案:

答案 0 :(得分:1)

您可以使用flat

var code = [
  [{Adults:"1", Price: "14.50"}],
  [{Adults:"1", Price: "20.50"}]
]

let op = code.flat()

console.log(op)