求json对象合并的方法
var a ={"a":"1","b":"2"}
var b ={"c":"3","d":"4","e":"5"}
想得到结果:
var c ={"a":"1","b":"2","c":"3","d":"4","e":"5"}
怎么弄??
var b ={"c":"3","d":"4","e":"5"}
想得到结果:
var c ={"a":"1","b":"2","c":"3","d":"4","e":"5"}
怎么弄??
==================
<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]);
alert(c.a);
</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]);
alert(c.a);
</script>