Merge Array to Object Array JavaScript

后端 未结 5 1344
醉梦人生
醉梦人生 2021-01-23 09:00

I have an array here:

var array = [
    [
        [\'firstName\', \'Nork\'], [\'lastName\', \'James\'], [\'age\', 22], [\'position\', \'writer\']
    ],
    [
           


        
5条回答
  •  春和景丽
    2021-01-23 09:11

    See this one:

    var array = [
        [
            ['firstName', 'Nork'], ['lastName', 'James'], ['age', 22], ['position', 'writer']
        ],
        [
            ['firstName', 'James'], ['lastName', 'Rodel'], ['age', 25], ['position', 'programmer']
        ]
    ];
    
    function changeData(array)
    {
        var i,j;
        var ret = [];
        var tmp = {};
    
        // rotate through every line and create a temporary object which we push to the return array
        for (i=0;i

提交回复
热议问题