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

194
Views
Array.from(new Array(init)) vs new Array

Does anyone have a strong understanding of how this shallow copy approach could impact a .map method? In short, what is the difference between:

Method 1:

const ratingArray = Array.from(new Array(Math.floor(rating)));

vs.

Method 2:

const ratingArray = new Array(Math.floor(rating));

in terms of their impact on this snippet:

{ratingArray.map(() => (
            <SvgXml xml={star} width={20} height={20} />
          ))}

I've been working through a tutorial and noticed this on line 51 in this file https://github.com/mobinni/MealsToGo/blob/14-rating/src/features/restaurants/components/restaurant-info-card.component.js#L51. When playing around with them, it does seem to impact the behavior of .map, so I really don't understand what's going on under the hood here.

Wouldn't using Array.from just create an additional shallow copy? I don't understand why that is necessary, but if you use Method 2 it doesn't appear to function as expected.

about 4 years ago · Juan Pablo Isaza
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!