var brands = [];
brands = [null, {
"id": "1",
"image": "/images/brands/surf_excel.png",
"name": "Surf Excel",
"productCount": "6"
}, {
"id": "2",
"image": "/images/brands/rin.png",
"name": "Rin",
"productCount": "5"
}, {
"id": "3",
"image": "/images/brands/ariel.png",
"name": "Ariel",
"productCount": "4"
}];
现在我想获取id为3的名称。 我尝试过
var data = _.filter(brands, { 'id': 3 });
console.log(data.name);
但是它会报错,无法读取未定义的属性。假设只有一条记录的id = 3,有人可以帮我吗?如何从上面的结构中获取给定id的名称。
如果有更好的方法来获得相同的结果,也将受到赞赏。
data.name
:) - Pranav C Balan