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

135
Vistas
Javascript map method: Wrapping the argument in curly braces results in an array of objects

I am trying to figure out why the following code results in an array of objects:

const startingArray = ['One', 'Two', 'Three', 'Four', 'Five'];

let endingArray = startingArray.map((nums) => {
  return { nums }
});

console.log(endingArray)

The result would be an array of objects such as:

[{nums: 'One'}
{nums: 'Two'}...]

and continuing on through the end of the input array... I understand that the map() method creates a new array populated with the results of calling a provided function on every element in the calling array. So is it simply a matter of the fact that by wrapping the argument in curly braces the map method inherently sets the argument name as the key of an object literal and sets the value of the input array as the associated value of the respective key?

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

0

{num} here is shorthand to {'num' : num} Checkout x in the below code:

let a = 22;
let x = { a};
console.log(x);

const startingArray = ['One', 'Two', 'Three', 'Four', 'Five'];

let endingArray = startingArray.map((nums) => {
    return {nums}
});

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