0
這是包含會計和銷售數組的對象數組employees
。是否可以在一次推送中將新條目添加到會計和銷售數組中?將對象添加到for循環中的'Json Array of Objects'
var employees = {
accounting: [ // accounting is an array in employees.
{
"firstName": "John", // First element
"lastName" : "Doe",
"age" : 23
},
{
"firstName": "Mary", // Second Element
"lastName" : "Smith",
"age" : 32
}
], // End "accounting" array.
sales: [ // Sales is another array in employees.
{
"firstName": "Sally", // First Element
"lastName" : "Green",
"age" : 27
},
{
"firstName": "Jim", // Second Element
"lastName" : "Galley",
"age" : 41
}
] // End "sales" Array.
} // End Employees
'employees.accounting.push(...)'?問題是什麼?你能向我們展示你正在嘗試使用的'for'循環嗎? – JLRishe 2014-09-18 19:31:05
我只是擔心從三個不同的數組中挑選來創建單個對象。沒有什麼是錯誤的推動。 for(i = 0; i
Jude
2014-09-18 19:35:35
好吧,我不知道我們應該猜測,當你從來沒有告訴過我們'arrayfirstname','arraylastname'和'arrayage'。請努力在您提出的問題中包含所有相關信息。 – JLRishe 2014-09-18 19:38:22