简体   繁体   English

如何存储一个小于前三个值的数组?

[英]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.

相关问题 如何从数组中获取小于 100 的所有值? - How do I get all values from an Array that are less than 100? 如何找到小于Java数组中x的第一个元素? - How to find first element that's less than the x in an array in Javascript? 如何使用小于和大于 javascript 的条件删除数组值 - How to remove array values using condition less than and greater than in javascript 如何将标记为“价格”的所有 class 值存储到一个数组中以便对它们进行排序? - How do I store all my class values labeled "price" into an array so I can sort them? 如何找到等于或大于值的文档数组中的所有值 - How can i find all values in array of Docs which are equal or bigger than value 第二个datePicker不能选择一个小于第一个datePicker的日期 - Second datePicker can not select a date less than the first datePicker 当输入字段长度小于 7 时清除字段中的所有值 - Clear all values in fields when input field length is less than 7 如何将重复的CSS值存储在变量中,以减少代码的重复性? - How can I store the repeating css values in varialbles to make the code less repetitive? 如何使用 Jquery 将 2 个选择框中的所有选定值存储到数组中? - How to store all selected values from 2 select boxes into an array with Jquery? 正则表达式-如何匹配小于或等于二十四的所有数字? - Regular Expression - How can I match all numbers less than or equal to Twenty Four?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM