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

200
Vistas
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
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