![](/img/trans.png)
[英]How do I access properties of an object that's inside of an array that's inside of an array that's inside of an array?
[英]What can I do to access to the properties of an object inside a nested array?
我有一個名為sportPromise
的數組,看起來像:
0: Array[0]
1: Array[1]
2: Array[2]
3: Array[3]
做console.log(angular.toJson($scope.sportPromise, 'pretty'));
退貨
[
[],
[
{
"id": 5932,
"parent": 1000,
"name": "NBA",
"sport": {
"id": 8,
"name": "NBA"
},
"lineType": "G",
"priority": [
1,
3
],
"part": "0"
}
],
[
{
"id": 2599,
"parent": 1000,
"name": "NCAA BASKETBALL",
"sport": {
"id": 24,
"name": "College Basketball"
},
我需要訪問嵌套在該數組中的對象的name
屬性,如您所見,它也是一個嵌套數組。
有什么建議么?
我在Angular中使用lodash
。
您可以使用$scope.sportPromise[n][0].name
訪問該屬性。
您可以通過遍歷每個嵌套范圍來訪問它:
for (var i=0; i< sportPromise.length; i++) {
for (var j=0; j < sportPromise[i].length; j++) {
console.log( sportPromise[i][j]['name'] );
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.