How to combine two arrays of objects into a single array and object using javascript
P粉254077747
P粉254077747 2024-04-05 10:00:36
0
1
1455

I want to know how to merge two arrays of objects into a single array using javascript

var arr1 = [
  {编号:1, name: "xxx"}
]

var arr2 =[
 {详细信息:“财务”, 费用:“100”}
]

Tried.
var result1 = [...arr1, ...arr2];
var result=Object.assign({}, ...result1)

Expected output [ { Number: 1, Name: "xxx", Details: "Finance", Cost: "100" } ]

P粉254077747
P粉254077747

reply all(1)
P粉955063662

var arr1 = [
  {id:1, name: "xxx"}
]

var arr2 =[
 {details:"finance", cost:"100"}
]

const result = arr1.map((item, index) => ({ ...item, ...arr2[index] }))

console.log(result)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!