我有一個現有的對象文字:var words=[ {"word":"callous","definition":"uncaring","examples": [ {"sentence":"How could you be so callous?"}, {"sentence":"What a callous thing to say!"}, {"sentence":"That showed a callous disregard for the consequences."}]}];我正在嘗試動態添加更多對象,如下所示:var obj={};obj.word="nextword";obj.definition ="nextword definition";obj.examples= ???;for (var i = 0; i < nextwordSentencesArray.length; i++) { ??? obj.examples.sentence.push(nextwordSentencesArray[i]);}words.push(obj);我在 -???- 嘗試了各種選項,但沒有任何效果。感激地收到建議。
如何將帶有數組鍵的對象動態添加到對象字面量?
慕尼黑5688855
2021-10-14 13:23:02