We have shared many articles about json objects. This article mainly introduces the method of merging json objects in JS, involving related operation skills of javascript recursive calls and json format data traversal. Friends who need it can refer to it. I hope it can help everyone. .
1. Question:
How to merge json objects
var a ={"a":"1","b":"2"} var b ={"c":"3","d":"4","e":"5"}
Want to get the result:
var c ={"a":"1","b":"2","c":"3","d":"4","e":"5"}
2. Implementation code:
##
<script> function extend(des, src, override){ if(src instanceof Array){ for(var i = 0, len = src.length; i < len; i++) extend(des, src[i], override); } for( var i in src){ if(override || !(i in des)){ des[i] = src[i]; } } return des; } var a ={"a":"1","b":"2"} var b ={"c":"3","d":"4","e":"5"} var c = extend({}, [a,b]); console.log(c); </script>
Manipulate JSON objects in Javascript and add a simple implementation of deletion and modification
Detailed explanation of jquery traversal and adding Json object code examples
Detailed explanation of JavaScript json object and array conversion simple implementation method example
Detailed explanation of JS operation of converting xml object into Json object
js Analysis of the method of converting json string into json object
The above is the detailed content of JS merge json object instance. For more information, please follow other related articles on the PHP Chinese website!