【es6】將2個數組合並為一個數組


//第一種  一個數組中的值為key 一個數組中的值為value
let arr1 = ['內存','顏色','尺寸'];
let arr2 = [1,2,3];
let temp = arr1.map((value,index,arr) => {
    let json = {};
    json[value] = arr2[index]
    return json
});
console.log(temp);

//第二種  一個數組中的值為對象['desc']值 一個數組中的值為對象['name']的值            
let result = arr1.map((value,index) => ({desc:value, name:arr2[index]}));
console.log(result);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM