Javascript 将数组元素添加到现有对象数组中
我正在努力研究如何将数组的元素添加到对象数组中。我有一个对象数组:Javascript 将数组元素添加到现有对象数组中,javascript,arrays,Javascript,Arrays,我正在努力研究如何将数组的元素添加到对象数组中。我有一个对象数组: 0: (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] 1: (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] 2: (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…},
0: (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
1: (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
2: (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
...etc
我有一个包含字符串的数组:
const titles = ["some title A", "some title B", "some title C"]
所以我的目的是,我想让我的数据如下:
[
{results: my_existing_array_of_object, title: "some title A"},
{results: my_existing_array_of_object, title: "some title B"},
{results: my_existing_array_of_object, title: "some title C"},
]
怎么做?提前感谢可以使用函数获取所需阵列:
const titles=[“一些标题A”、“一些标题B”、“一些标题C”]
const other=[{id:1},{id:2},{id:3},{id:4}]
const result=other.map((o,i)=>({results:o,
标题:(i console.log(结果)
我根据
const titles=[“一些标题A”、“一些标题B”、“一些标题C”]
const other=[{id:1},{id:2},{id:3},{id:4}]
const result=other.map(((o,i)=>({results:o,//添加新键
标题:(i console.log(result)
titles.map((title)=>({results:resultsArray,title}))代码>?非常感谢,它对我有效,我做了一些调整,因为我需要一把新钥匙。[链接]()