Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda