仅举例说明我要做的事情:
item1.item2
//item2 has four objects
//object0, object1, object2, object3
//each object has the same property within it 'propTitle'
我需要获取所有4个对象的propTitle值。我需要做些什么才能做到这一点?
答案 0 :(得分:4)
var titles = $.map(item1.item2, function(v, i) {
return v.propTitle;
});
或者没有jQuery,假设item1.item2
是一个数组...
var titles = item1.item2.map(function(v, i) {
return v.propTitle;
});
虽然您需要一个补丁来支持旧浏览器。
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map#Compatibility