Js array operation

let arr1 = ["a","b","c"];
let arr2 = ["d","e","f"];

how to become

let arr3 = [{"key1":"a","key2":"d"},{"key1":"b","key2":"e"},{"key1":"c","key2":"f"}];
May.05,2021

let arr3 = arr1.map((item,index)=>({
    key1:item,
    key2:arr2[index] || ''
}))

var arr1 = ['a','b','c'];
var arr2 = ['d','e','f'];
let arr3 = arr1.map(function(val,index)=>{
    return {'key1':val,'key2':arr2[index]};
});

is the data structure always the same length?
for fault-tolerant processing, it is recommended to compare the length of two arrays in advance, and then cycle the array with large length to avoid data loss.

Menu