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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -