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

196
Visualizações
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 à 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