关于javascript:js实现两个数组一一对应

42次阅读

共计 332 个字符,预计需要花费 1 分钟才能阅读完成。

var arrA = [‘weibo’, ‘work’]
var arrB = [{index_template: ‘1’, count: 10, scroll_play_pic: ‘0’},{index_template: ‘2’, count: 20, scroll_play_pic: ‘2’}]

    var info = {};
    function ArrayToObj(arrA, arrB) {for(var i = 0; i < arrA.length; i++) {info[arrA[i]] = arrB[i];
        }
        
        return info;
        }
            ArrayToObj(arrA, arrB);
            console.log(info);
    for(var key in info){console.log(key+':'+info[key])
    }  

最终后果

正文完
 0