串联阵列本身以复制它 [英] Concatenate array to itself in order to duplicate it
本文介绍了串联阵列本身以复制它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在的Python
:
>>> [1,2,3,4] * 2
[1,2,3,4,1,2,3,4]
什么是去与的JavaScript
?
目前使用:
VAR数据= [1,2,3,4];
data.concat(数据);
// [1,2,3,4,1,2,3,4]
解决方案
您不能繁殖数组在JavaScript中。使用当前解决方案的 Array.concat 是正确的。
注意,它创建具有复制的项目的单独阵列,并且不改变原始。
In Python
:
>>> [1,2,3,4] * 2
[1, 2, 3, 4, 1, 2, 3, 4]
What is the way to go with JavaScript
?
Currently using:
var data = [1,2,3,4];
data.concat(data);
//[1, 2, 3, 4, 1, 2, 3, 4]
解决方案
You can't multiply arrays in JavaScript. Your current solution using Array.concat is correct. Note that it creates a separate array with the copied items, and does not alter the original.
这篇关于串联阵列本身以复制它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文