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

210
Vistas
Confused on github copilot solution that works but not sure why

So I was stuck on a bug in my React App (I am new to react and JS in general) where I wanted to filter a list of company names so that they are all unique and dont repeat. So having access to github copilot I turned it on and out came a solution that worked but I have no idea why or what its doing. If anyone could help me?

    useEffect(() => {
        const companyNames = data.map(app => app.companyName);
        const uniqueCompanies = [...new Set(companyNames)];
        setCompanies(uniqueCompanies);
    },[data]);

I dont understand how [...new Set(companyNames)] filters out the unique names or what is happening. To my understanding you can only use the spread operator on an array that already exists so didn't know where the new was coming from either.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The expression const uniqueCompanies = [...new Set(companyNames)]; contains the following interesting properties:

  • [] is an array literal
  • new Set(companyNames) a new JavaScript Set that can contain only unique values by design, providing the filtering "out of the box".
  • ... The array spread operator here will spread the Set to Array, thus effectively converting the Set to Array.
about 4 years ago · Juan Pablo Isaza Denunciar
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