concat方法: 是合并数组使用(原数组不发生变化,返回一个合并后的新数组)
var arr1 = ["arr1", "arr1", "arr1", "arr1"];
var arr2 = ["arr2", "arr2", "arr2", "arr2"];
var arr3 = arr1.concat(arr2);//这样这两个数组就被合并了 而且我们可以发现原来的两个数组都没有发生改变
console.log(arr1); // ["arr1", "arr1", "arr1", "arr1"];
console.log(arr2); // ["arr2", "arr2", "arr2", "arr2"];
console.log(arr3); // ["arr1", "arr1", "arr1", "arr1", "arr2", "arr2", "arr2", "arr2"]//如果是多维数组的合并
var arr4 = ["arr4", "arr4", ["arr4", "arr4"]];
var arr5 = arr1.concat(arr4);//我们来打印这个数组 得到的结果会是?
console.log(arr5); // ["arr1", "arr1", "arr1", "arr1", "arr4", "arr4", Array(2)]//可以看到有一个特别的数组Array(2)在最后 试着打印看看它 arr5.length-1得到最后一个下标
console.log(arr5[arr5.length-1]) //["arr4", "arr4"]//所以 这下我们知道了 如果是多维数组 只把最外层的数组拆开 其他的内层数组不变//获取多维数组的值的方法:
console.log(arr5[6][1]) // "arr4"