求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"}
怎么弄??
==================
<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>
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow
原文地址:https://www.cnblogs.com/skiwndhw/p/10351996.html
时间: 2024-10-21 14:40:00