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

85
Vistas
Convert array of data into an object with properties

How do I convert an array into an object with properties: With the following data: ["Test Scenario ID", "Login-1"]

I would like to return an object with properties:

{1: "Test Scenario ID", 2: "Login-1"} // desired result

With the following, It maps the data into separate objects, but I would like it to be properties of a single object instead of an array of objects:

row.values.map( (e,i) => { return {i: e} })

[{1: "Test Scenario ID"}, {2: "Login-1"}] // the current result
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

One option is to use Object.fromEntries to turn an array of entries into the object.

const result = Object.fromEntries(
  row.values.map((e, i) => [i, e])
);

Another option is to take your array of multiple objects and put it through Object.assign to combine them.

const result = Object.assign(
  ...row.values.map( (e,i) => ({i: e}))
);
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can use this:

Object.assign({}, ['a','b','c']);    // {0:"a", 1:"b", 2:"c"}

The Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It returns the modified target object.

you can read more about it here on MDN

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