数据拼接
有一个数组
let arr1 = [
{name:''lili",age:14},
{name:''小明",age:16},
{name:''张三",age:24},
]
let arr2 = [
{class:"初一二班",gender:"0"},
{class:"初一三班",gender:"1"},
{class:"初一五班",gender:"1"},
]
let newArr = []
this.newArr= this.arr1.map((item,index)=>{ return {...item, ...this.arr2[index]} }) 最后输出的结果为 newArr=[{name:''lili",age:14,class:"初一二班",gender:"0"},
{name:''小明",age:16,class:"初一三班",gender:"1"},
{name:''张三",age:24,class:"初一五班",gender:"1"},
] 若是数据结构单一的数组拼接(数组里面不嵌套对象)ES6数组解构(...array)实现数组复制
vararr1=['a','b','c','d'];
vardd=[...arr1];
dd[]='es6';
console.log(dd);//["es6", "b", "c", "d"]
console.log(arr1);//["a", "b", "c", "d"]
数组concat方法,实现数组复制
var arr1=['a','b','c','d'];
var cc=arr1.concat();
cc[1]='yy';
console.log(arr1);//["a", "b", "c", "d"]
console.log(cc);//["a", "yy", "c", "d"]
通过es6数组解构实现数组合并
var arr1=['a','b','c','d'];
var arr2=['d'];
var arr3=['e','f'];
var dd=[...arr1,...arr2,...arr3];
console.log(dd);//["a", "b", "c", "d", "d", "e", "f"]
通过concat方法实现数组合并
var arr1=['a','b','c','d'];
var arr2=['d'];
var arr3=['e','f'];
var cc=arr1.concat(arr2,arr3);
console.log(cc);//["a", "b", "c", "d", "d", "e", "f"]
标签:...,console,数组,下有,arr1,var,数据结构,log From: https://www.cnblogs.com/yangzhulian/p/16738474.html