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

106
Vistas
convert array to array of objects using JS

I need a help, how to convert an array to array of objects.

Eg: may be this is the array

let a = ["abc", "mno"]

I want it to be like this:

let b = [
  {
    "text": "abc"
  },
  {
    "text": "mno"
  }
]

please help me to fix this. Thanks.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

const a = [ "abc", "mno" ];
const b = a.map( ( item ) => { return {text:item} } );

console.log('a => ', a)
console.log('b => ', b)

explanation :

array.map is looping to every element of the array and if you provide return it will create new array from the return of every element

in this case the return is an object of { text:item } by item being the element of which index on the loop

about 4 years ago · Juan Pablo Isaza Denunciar

0

.map() with arrow notation should do it:

.map() -> loops over an array and returns a transformed array. With arrow functions you need not right return statement if you skip the curly braces along. Enclose them in parentheses (()) whenever you want to return an object.

let a = ["abc", "mno"];
let b = a.map(item => ({"text" : item}));
console.log(b);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can make use of array.forEach and array.push function to do so.

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