[英]How can store an array all values less than the first 3?
I have this example: 我有这个例子:
var array=[0.1,2,3,4,6,7,8,9]
What I want is to store it in a variable only those values 我想要的是将其仅存储在那些值中
var newArray=[3,4,6,7,8,9]
Of course, this must be dynamic ... regardless of the number of elements to store more than the first 3 items. 当然,这必须是动态的...无论要存储的元素数量多于前3个项目。
You need to use JavaScript's slice
: 您需要使用JavaScript的
slice
:
var array = [0.1,2,3,4,6,7,8,9];
var newArray = array.slice(2);
// [3, 4, 6, 7, 8, 9]
Read more here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/slice 在此处阅读更多信息: https : //developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
Usage : arr.slice([begin[, end]])
用法 : arr.slice([begin [,end]])
slice
does not alter.slice
不会改变。 It returns a shallow copy of elements from the original array.它返回原始数组中元素的浅表副本。 Elements of the original array are copied into the returned array.
将原始数组的元素复制到返回的数组中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.