- es6中的方法
flat() - push.apply()
const a = [1]
let b = [2, 4, 6]
let c = [11, 12, 13]
a.push.apply(a, b)
console.log(a) // [1, 2, 4, 6]
a.push(c)
console.log(a.flat()) // [1, 2, 4, 6, 11, 12, 13]
const a = [1]
let b = [2, 4, 6]
let c = [11, 12, 13]
a.push.apply(a, b)
console.log(a) // [1, 2, 4, 6]
a.push(c)
console.log(a.flat()) // [1, 2, 4, 6, 11, 12, 13]
本文标题:合并两个数组组成一个新的数组
本文链接:https://www.haomeiwen.com/subject/wywtictx.html
网友评论