裏面我有一個JavaScript對象,它是DYNAMICALLY CREATED
這樣添加到陣列陣列
[
{"user":"James","errors":["signature must be signed!"]},
{"user":"Jones","errors":["signature must be signed!"]}
]
我試圖在該對象內的errors
陣列動態添加新的錯誤。
這是我曾嘗試:
validationErr.push({ "user" : "James", "errors" : ["start time musst be filled!"] });
但我得到一個新條目
[
{"user":"James","errors":["signature must be signed!"]},
{"user":"Jones","errors":["signature must be signed!"]},
{"user" : "James", "errors" : ["start time musst be filled!"]}
]
,而不是這個
[
{"user":"James","errors":["signature must be signed!", "start time musst be filled!"]},
{"user":"Jones","errors":["signature must be signed!"]},
]
我如何可以添加到裏面現有陣列我目的?
這是0也硬編碼? – lewis4u
@ lewis4u是的,如果用戶== James是唯一的,你會在過濾後得到一個單獨的數組,所以需要使用該選擇器獲取它。 –
如果我的對象是動態創建的呢? – lewis4u