我有对象的数组如下:如何从对象数组的属性返回数组
var lanes = [
{
"name" : "Breakfast Special",
"className" : "breakfast-special",
"sales" : 200,
"redemptions" : 137
},
{
"name" : "Free Danish",
"className" : "free-danish",
"sales" : 300,
"redemptions" : 237
},
{
"name" : "Half Price Coffee",
"className" : "half-price-coffee",
"sales" : 240,
"redemptions" : 37
}];
我想创建一个包含存储“赎回”只是数值数组。我可以访问的值为:
lanes[0].redemptions;
通过使用循环遍历每个对象,但我正在寻找一些有效的方法来做到这一点。
这个我试过使用地图功能如下:
var arrayRedemptions = lanes.map(function() {return this.redemptions});
但它不工作。任何帮助,将不胜感激。
这些都是对象常量,不“JSON对象”。这是一个相当普遍的误解(http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/)。 –