数组转化为对象

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"}

posted @ 2021-11-17 10:20  小小小小小前端  阅读(289)  评论(0编辑  收藏  举报