数组转化为对象

var a = [{src:"websrv1"}, {dst:"websrv2"}, {dstport:"80"}]; var b = a.reduce( function(reduced,next){ Object.keys(next).forEach(function(key){reduced[key]=next[key];}); return reduced; } ); //b should be {src:"websrv1", dst:"websrv2", dstport:"80"}

不求大富大贵,但求一生平凡
原文地址:https://www.cnblogs.com/ylblogs/p/15566018.html