我有這個數組定義:轉換的Javascript對象的數組到1陣列
$scope.exportData = [];
,然後我做一個API調用,並返回我的數組3個對象。
[Object, Object, Object] //from Console Log
0: Object
Name: "Steve"
Age: 30
Sex: "M"
1: Object
Name: "James"
Age: 25
Sex: "M"
2: Object
Name: "Joe"
Age: 20
Sex: "M"
什麼,我期待在這裏做的是採取了對象$ scope.exportData內,並把它們在數組中,所以我有$ scope.exportData內5個陣列,像這樣:
[Array[3], Array[3], Array[3]]
0: Array[3]
"Name" : "Steve"
"Age" : 30
"Sex" : "M"
1: Array[3]
"Name" : "James"
"Age" : 25
"Sex" : "M"
2: Array[3]
"Name" : "Joe"
"Age" : 20
"Sex" : "M"
如何我會這樣做嗎?謝謝,任何幫助,將不勝感激
爲什麼你會真正想做的事就是這樣,其目的是更容易訪問,則數組的集羣。 – Bharath
我有遍歷每個數組並放入csv文件的代碼,使得數組中的這些對象對我來說更容易。 – user3723240
不能,一個數組只能有數字索引,而不能是鍵/值對,因爲它會是一個對象。 – adeneo