Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!