gpt4 book ai didi

javascript - 如何使用javascript合并以下格式的两个对象数组

转载 作者:行者123 更新时间:2023-12-01 06:42:58 24 4
gpt4 key购买 nike

array1 = [{
questionId: "5e52b55330bb2cee102b9a39",
note: "Name",
prefillValue: "prasanna"
},

{
questionId: "5e52b56b30bb2cee102b9a3f",
note: "Mobile Number",
prefillValue: null
},
{
questionId: "5e52b58230bb2cee102b9a42",
note: "Agent Email",
prefillValue: null
},
{
questionId: "5e52b55e30bb2cee102b9a3c",
note: "Email",
prefillValue: null
},
{
questionId: "5e52c39730bb2cee102b9a47",
note: "Agent ID",
prefillValue: null
},
{
questionId: "5e54dbdd30bb2c6018f488ca",
note: "Location",
prefillValue: null
}
]


array2 = [{
questionId: "5e52b55e30bb2cee102b9a3c",
note: "Email",
prefillValue: "skk@gmail.com"
},
{
questionId: "5e52c39730bb2cee102b9a47",
note: "Agent ID",
prefillValue: "34"
},
{
questionId: "5e54dbdd30bb2c6018f488ca",
note: "Location",
prefillValue: "Chennai"
}
]

预期输出:

array3 = [{
questionId: "5e52b55330bb2cee102b9a39",
note: "Name",
prefillValue: "prasanna"
},

{
questionId: "5e52b56b30bb2cee102b9a3f",
note: "Mobile Number",
prefillValue: null
}, {
questionId: "5e52b58230bb2cee102b9a42",
note: "Agent Email",
prefillValue: null
}, {
questionId: "5e52b55e30bb2cee102b9a3c",
note: "Email",
prefillValue: null
}, {
questionId: "5e52b55e30bb2cee102b9a3c",
note: "Email",
prefillValue: "skk@gmail.com"
}, {
questionId: "5e52c39730bb2cee102b9a47",
note: "Agent ID",
prefillValue: "34"
},
{
questionId: "5e54dbdd30bb2c6018f488ca",
note: "Location",
prefillValue: "Chennai"
}
]

最佳答案

let array1 = [{
questionId: "5e52b55330bb2cee102b9a39",
note: "Name",
prefillValue: "prasanna"
},

{
questionId: "5e52b56b30bb2cee102b9a3f",
note: "Mobile Number",
prefillValue: null
},
{
questionId: "5e52b58230bb2cee102b9a42",
note: "Agent Email",
prefillValue: null
},
{
questionId: "5e52b55e30bb2cee102b9a3c",
note: "Email",
prefillValue: null
},
{
questionId: "5e52c39730bb2cee102b9a47",
note: "Agent ID",
prefillValue: null
},
{
questionId: "5e54dbdd30bb2c6018f488ca",
note: "Location",
prefillValue: null
}
]


let array2 = [{
questionId: "5e52b55e30bb2cee102b9a3c",
note: "Email",
prefillValue: "skk@gmail.com"
},
{
questionId: "5e52c39730bb2cee102b9a47",
note: "Agent ID",
prefillValue: "34"
},
{
questionId: "5e54dbdd30bb2c6018f488ca",
note: "Location",
prefillValue: "Chennai"
}
]

let array3 = [...array1,...array2];

console.log(array3)

关于javascript - 如何使用javascript合并以下格式的两个对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60762531/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com