我有對象的數組這就好比推新元件在多維數組obj的陣列的javascript
[
{
"id" : 1,
"title" : "name1",
"description" : "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, nesciunt hic aut? Saepe nihil autem nesciunt, ab quisquam animi, aperiam fugit? Ut velit a, in perspiciatis error inventore. Dolorum, eligendi.",
"image" : "sampledata/products/1.jpg",
"price" : 10
},
{
"id" : 2,
"title" : "name2",
"description" : "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, nesciunt hic aut? Saepe nihil autem nesciunt, ab quisquam animi, aperiam fugit? Ut velit a, in perspiciatis error inventore. Dolorum, eligendi.",
"image" : "sampledata/products/2.jpg",
"price" : 100
},
{
"id" : 3,
"title" : "name3",
"description" : "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, nesciunt hic aut? Saepe nihil autem nesciunt, ab quisquam animi, aperiam fugit? Ut velit a, in perspiciatis error inventore. Dolorum, eligendi.",
"image" : "sampledata/products/3.jpg",
"price" : 200
}
]
和我要添加新元素的每個OBJ這樣的,「計數「:12,我試圖使用.push來做到這一點,但它會將數添加到數組的末尾而不是將其添加到每個obj,我該如何解決這個問題?
您可以添加你的JavaScript代碼,或者與你的代碼Plunkr因爲它是目前? –
順便說一下,它不是一個真正的多維數組(它將是[[],[],[]]),它的一個對象數組 –