Search code examples
javascriptarraysobjectreducedestructuring

Need help in this array destructuring and intialize value in object


let Arr = ["a","b","'c','d'","e","f"]

need to store value in object like with fixed key name

obj = {hey: "a", hello: "b", how: "'c','d'",are: "e",you:"f"}

Solution

  • Try

    Arr.reduce((a,c,i)=> (a[keys[i]]=c,a),{});
    

    let Arr = ["a","b","'c','d'","e","f"];
    let keys = ["hey","hello","how","are","you"];
    
    let obj = Arr.reduce((a,c,i)=> (a[keys[i]]=c,a),{});
    
    console.log(obj);