0
無法弄清楚這一點。使用array.push構建JSON數組
var states = [];
for(var i = 0; i<transactions.length; i++){
var state = {name: transactions[i].name, amount: transactions[i].amount}
console.log(state)
states.push[state];
console.log(states)
}
只是試圖將一組縮減的交易數據放在一起作爲「狀態」。
我打印控制檯看起來像:
{ name: 'United Airlines', amount: -500 }
[]
{ name: 'McDonald\'s', amount: 12 }
[]
{ name: 'Starbucks', amount: 4.33 }
[]
{ name: 'SparkFun', amount: 89.4 }
[]
{ name: 'INTRST PYMNT', amount: -4.22 }
[] <<<<<nothing in my states array?
states.push(state); – Nevosis
您使用錯誤類型的括號用於推送... – Li357