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

114
Vistas
How to add to a set without mutating it?

I want to add an item to a Set without mutating the original set. I tried using add() but this mutates the original:

var s = new Set();
var s1 = s.add('foo');
console.log('s has foo:', s.has('foo'));
console.log('s1 has foo:', s1.has('foo'));

How can I create a new set by adding an item to it, without mutating the original set?

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

0

You can create a new set from the original, then add the item to the new set:

var s = new Set();
var s1 = new Set(s);
s1.add('foo');
console.log('s has foo:', s.has('foo'));
console.log('s1 has foo:', s1.has('foo'));

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