Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
How to make the nested items of array to object?

I have a nested array like this:

var arr = [
            ['Simcard', 'one'],
            ['Charge', 'two'],
          ];

I want to make it like this:

[
   {"Simcard": "one"},
   {"Charge": "two"},
]

How can I do that?


Here is what I've tried but not exactly the expected result:

let res = Object.keys(x).map((key) => {key: x[key]});
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

There's a builtin Object.fromEntries that turns a two-element array into an object.

var arr = [
            ['Simcard', 'one'],
            ['Charge', 'two'],
          ];

var desired = [
   {"Simcard": "one"},
   {"Charge": "two"},
]

var answer = arr.map(entry => Object.fromEntries([entry]));

console.log(answer)

about 4 years ago · Juan Pablo Isaza Denunciar

0

This is not a oneliner, but you could try the following

let res = []
arr.forEach(element => res[element[0]] = element[1])
about 4 years ago · Juan Pablo Isaza Denunciar

0

let res = arr.map(item => ({[item[0]]: item[1]}))
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda