[removed] Convert Array to Object

后端 未结 6 1227
执念已碎
执念已碎 2021-01-16 03:19

Which is the easiest way to convert this:

[{src:\"websrv1\"}, {dst:\"websrv2\"}, {dstport:\"80\"}]

to this:

{src:\"websrv1\         


        
6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 03:37

    If you are using jquery, try this:

    var array = [{src:"websrv1"}, {dst:"websrv2"}, {dstport:"80"}]
    var arrayObj = {};
    
    for(var i in array) {
        $.extend(arrayObj, array[i]);
    }
    

提交回复
热议问题