0

I have to convert an array of arrays into an object and I don't know how to do it. I have tried this way but the result is not what I expected.I don't know how to return

input = [[ 'Thundercats', '80s' ], [ 'The Powerpuff Girls', '90s' ], [ 'Sealab 2021', '00s' ]];

function objectify(array){
  
    array.forEach(el=>{
      el.reduce(function(result, item,index,array){
        result[index] = item;
        return result;
      }, {})    
  })
  
  return ??;
}

console.log(objectify(input))

Una solución con una sola línea:

const obj = Object.fromEntries(array);
A.Baes
  • 113
  • 9
  • 1
    `Object.fromEntries(input)` – Ivar Oct 20 '21 at 19:28
  • Familiarize yourself with [how to access and process nested objects, arrays or JSON](/q/11922383/4642212) and how to [create objects](//developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Object_initializer) and use the available static and instance methods of [`Object`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object#Static_methods) and [`Array`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array#Static_methods). – Sebastian Simon Oct 20 '21 at 19:29

0 Answers0