let arr1 = [{id: 1, name: 'Tom'}, {id: 2, name: 'Jerry'}];
let arr2 = [{id: 3, name: 'Lily'}, {id: 4, name: 'Lucy'}];
let combinedArr = arr1.concat(arr2); // 合并两个数组
console.log(combinedArr); // [{id: 1, name: 'Tom'}, {id: 2, name: 'Jerry'}, {id: 3, name: 'Lily'}, {id: 4, name: 'Lucy'}]
  • 使用 spread (...) 运算符:利用该运算符可以将一个数组展开成单独的元素,可以用于同时连接多个数组对象。
  • let arr1 = [{id: 1, name: 'Tom'}, {id: 2, name: 'Jerry'}];
    let arr2 = [{id: 3, name: 'Lily'}, {id: 4, name: 'Lucy'}];
    let arr3 = [{id: 5, name: 'John'}, {id: 6, name: 'Jenny'}];
    let combinedArr = [...arr1, ...arr2, ...arr3]; // 合并三个数组
    console.log(combinedArr); // [{id: 1, name: 'Tom'}, {id: 2, name: 'Jerry'}, {id: 3, name: 'Lily'}, {id: 4, name: 'Lucy'}, {id: 5, name: 'John'}, {id: 6, name: 'Jenny'}]
    

    以上两种方法都可以达到合并多个数组对象的效果,具体使用哪种方法取决于实际情况和个人偏好。

  •