两个数字,包容性,在Javascript / jQuery的创建之间的所有整数数组 [英] Create array of all integers between two numbers, inclusive, in Javascript/jQuery
本文介绍了两个数字,包容性,在Javascript / jQuery的创建之间的所有整数数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有以下复选框:
<输入类型=复选框值=1-25/>
要获取定义的范围我要找的界限,我用下面的jQuery的两个数字:
VAR值= $(本).VAL();
变种lowEnd =号码(value.split(' - ')[0]);
变种高端=号码(value.split(' - ')[1]);
我如何再创建一个包含 lowEnd
和高端
,其中<$ C $之间的所有整数数组C> lowEnd 和高端
自己?对于这个具体的例子,很明显,所得到的阵列将是:
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 ,20,21,22,23,24,25]
解决方案
VAR名单= [];
对于(VAR I = lowEnd; I&LT; =高端;我++){
list.push(ⅰ);
}
Say I have the following checkbox:
<input type="checkbox" value="1-25" />
To get the two numbers that define the boundaries of range I'm looking for, I use the following jQuery:
var value = $(this).val();
var lowEnd = Number(value.split('-')[0]);
var highEnd = Number(value.split('-')[1]);
How do I then create an array that contains all integers between lowEnd
and highEnd
, including lowEnd
and highEnd
themselves? For this specific example, obviously, the resulting array would be:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
解决方案
var list = [];
for (var i = lowEnd; i <= highEnd; i++) {
list.push(i);
}
这篇关于两个数字,包容性,在Javascript / jQuery的创建之间的所有整数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文