我需要在 Angular js 中获取给定索引的数组中的对象。
scope.storeList = [{
'id':101,
'name':indhu
},{
'id':102,
'name':selvin
},{
'id':103,
'name':indhu1
}];
在这里,如果我给出索引值,它应该给出对象。 我尝试了下面的代码但无法得到:
var list = scope.storeList[2];
请有人帮忙。
最佳答案
您的 JSON 对象中存在语法错误:字符串必须位于引号之间:
$scope.storeList = [{
'id':101,
'name':'indhu'
},{
'id':102,
'name':'selvin'
},{
'id':103,
'name':'indhu1'
}];
var list = $scope.storeList[2];
console.log(list); // prints Object { id: 103, name: "indhu1" }
<小时/>
<强> Try it on JSFiddle here (不要忘记打开控制台)。
关于angularjs - 如何在 Controller Angular js中获取带有索引的数组中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40259130/