[removed] Convert Array to Object

后端 未结 6 1236
执念已碎
执念已碎 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:32

    My 2cents, very easy to read:

    var myObj = {};
    myArray.forEach(function(obj) {
      var prop = Object.keys(obj)[0];
      myObj[prop] = obj[prop];
    })
    

提交回复
热议问题