javascript/jquery获得最低编号 [英] javascript/jquery get lowest number
本文介绍了javascript/jquery获得最低编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$("div").each(function(){
var index_no = $(this).index();
console.log(index_no);
});
我想获得最低的索引,但我不能这样做
I want to get lowest index but I can't do that
推荐答案
我想获得最低的索引,但我不能这样做
I want to get lowest index but I can't do that
确定您可以:0
JavaScript中任何数组的最低索引将为0.
The lowest index of any array is going to be 0 in JavaScript.
如果您有一个值数组,则可以这样获得最小值:
If you have an array of values, you can get the min as so:
var arr = [3,1,4];
Math.min.apply(Math, arr); // returns 1
给出您的codepen示例(您应在问题中包括该示例):
Given your codepen example (which you should include in your question):
var indexes = [];
$("div").each(function(i){
if(!$(this).hasClass("lo")){
indexes[indexes.length]=i;
}
});
console.log("Matches: ", indexes);
console.log("Min: ", Math.min.apply(Math,indexes));
这篇关于javascript/jquery获得最低编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文