举例说明
concat 不会改变原数组,而是返回一个新数组
let a = ['1','2','3']
let b = ['4','5','6']
a.concat(b)
console.log(a) // results in ['1','2','3']
let a = ['1','2','3']
let b = ['4','5','6']
a = a.concat(b)
console.log(a) // results in ['1','2','3','4','5','6']
合并多个数组
var num1 = [1, 2, 3],
num2 = [4, 5, 6],
num3 = [7, 8, 9]
var nums = num1.concat(num2, num3)
console.log(nums) // results in [1, 2, 3, 4, 5, 6, 7, 8, 9]
将值连接到数组
var alpha = ['a', 'b', 'c']
var alphaNumeric = alpha.concat(1, [2, 3])
console.log(alphaNumeric) // results in ['a', 'b', 'c', 1, 2, 3]
合并嵌套数组
var num1 = [[1]]
var num2 = [2, [3]]
var nums = num1.concat(num2)
console.log(nums) // results in [[1], 2, [3]]
num1[0].push(4)
console.log(nums) // results in [[1, 4], 2, [3]]