js将两个一维数组组成一个键值对的对象

var arr = ["a", "b", "c"];
var brr = [1, 2, 3];
var obj = {};
for (var i = 0; i < arr.length; i++) {
    obj[arr[i]] = brr[i]
}
console.log(obj) //{ a: 1, b: 2, c: 3 }


function transformObject(keyArr,valueArr) {
    var obj = {};
    keyArr.map( (v,i) => {
        obj[keyArr[i]] = valueArr[i];
    })
    return obj;
}

 

    原文作者:Neal__caffreal
    原文地址: https://blog.csdn.net/weixin_42265852/article/details/90414450
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞