javascript - Append New Json Element to JsonObject in Array of JsonObjects -
i have jsonarray , new jsonelements. want append jsonarray.
jsonarray=[{"a":"a1", "b":"b1"}, {"a":"a2", "b":"b2"}, ...] jsonelement = {"c":"c1", "d":"d1", ...}
now
jsonarray[0].c = jsonelement.c jsonarray[0].d = jsonelement.d
but element larger c & d , looks code. google finds me http://api.jquery.com/jquery.extend/. there exist javascript function that.
edit: make more clear. array of json elements (json array shorter). , don't want push want have json objects this:
jsonarray=[{"a":"a1", "b":"b1", "c":"c1", "d":"d1"}, {"a":"a2", "b":"b2"}, ...]
if expected output
jsonarray=[{"a":"a1", "b":"b1"}, {"a":"a2", "b":"b2"}, {"c":"c1", "d":"d1", ...}]
simply this:
jsonarray.push(jsonelement);
to see output this:
console.log(json.stringify(jsonarray));
Comments
Post a Comment