2017-02-21 31 views
-2

我得到这个数组在我的铬控制台,使用这种方法$("#gallery_thumbnails .owl-item.active").get();获得来自jQuery的数组索引对象

Array[5] 
0:div.owl-item.active 
1:div.owl-item.active.synced 
2:div.owl-item.active 
3:div.owl-item.active 
4:div.owl-item.active 

enter image description here

但我想只有数组指数法,像这样:

enter image description here

我该如何得到这个结果?

+0

如何获取'length'和创建你的拥有? – Rajesh

+1

对我来说毫无意义。 –

+0

如果指数等于它的价值,它有什么价值? –

回答

0

迭代您的对象数组并将键保存到新数组。

var out = []; 
for (key in arrays) { 
    out.push(key); 
} 
console.log(out); 

或者其他用户的建议,使用此方法:

var out = []; 
for (var i = 0; i < array.length; i++) { 
    out.push(i); 
} 
console.log(out); 
+0

'for..in'是为了遍历对象。它也会遍历其他属性,如长度。这些将在现代浏览器中跳过 – Rajesh

0

你可以使用map方法从jQuery

$.map($("#gallery_thumbnails .owl-item.active").get(), function (val, i) { 
    return i; 
});