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

509
Views
Are there differences between [...array].map(...) and [...array.map(...)] in JavaScript?

I can't quite understand the differences between [...array].map(...) and [...array.map(...)]. Are they any different? If yes, why and how?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

  • [...array].map(...) will generate a new shallow copy of an array ([...array]) and then .map over it and return a brand new array as the return value.
  • [...array.map(...)] will .map over the original array, which will return a new array, and then immediately make a shallow copy of the new array ([...array.map(...)]). I must admit, I don't really understand the use case for this approach-- because .map itself is returning a brand new array that no other variable should be holding a reference to, I don't see any value in immediately casting a shallow copy of it.

(Also, as pointed out by chazsolo in the comments, if array were not an array, but in fact some other type like a Set, the [...array.map(...)] approach would actually throw an error, as Set instances have no .map method).

about 4 years ago · Juan Pablo Isaza Report

0

Well [...array.map(...)] is the same as array.map(...) except that it does an extra unnecessary spread/copy after the mapping is done.

The [...array].map(...) has an small difference, due to the 3rd parameter passed in map (the array it self).

And as mentioned in another comment, by @chazsolo, this case will handle cases where the array variable is not an array, so it does not have the map method, but can be iterated and the spread will create an array out of it.

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!