按索引的Jquery数组键值

时间:2014-06-26 19:00:19

标签: jquery arrays key associative-array

我尝试从数组中获取键和值。 但我真的不明白如何获得索引的值/键...

这是我的脚本(我在循环中按下键和值,然后尝试获取与数组中某个位置对应的值):

var imgArr = [];
imgArr.push({"src":$(this).find('.lightbox').data('img-src'),"title":$(this).find('.lightbox').data('img-title')});

var index = 3;
$(LbImage).attr('src', imgArr[index].src);

使用console.log(imgArr)我得到:

[Object, Object, Object, Object, Object, Object, Object, Object, Object]
0: Object
src: "http://ddd/wp-content/uploads/sites/2/2013/12/stray-cat.jpg"
title: "stray cat"
__proto__: Object
1: Object
src: "http://ddd/wp-content/uploads/sites/2/2013/12/Birds.jpg"
title: "Birds"
__proto__: Object
2: Object
3: Object
4: Object
5: Object
6: Object
7: Object
8: Object
length: 9
__proto__: Array[0]

0 个答案:

没有答案