说我有一个数组:
[1,2,3]
Run Code Online (Sandbox Code Playgroud)
我想要一个数组:
[1,2,3,1,2,3]
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以在不循环遍历数组并推送每个元素的情况下进行此操作?
小智 8
您可以使用 Array.prototype.concat()
let array1 = [1,2,3]
console.log(array1.concat(array1))Run Code Online (Sandbox Code Playgroud)
您可以使用传播语法
let array = [1,2,3];
array.push(...array);
console.log(array)Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
98 次 |
| 最近记录: |