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

312
Vistas
How to convert Set to string with space?

I want to convert JavaScript Set to string with space.

For example, if I have a set like:

var foo = new Set();
foo.add('hello');
foo.add('world');
foo.add('JavaScript');

And I'd like to print the string from the set: hello world JavaScript (space between each element).

I tried below codes but they are not working:

foo.toString(); // Not working
String(foo); // Not working

Is there simplest and easiest way to convert from Set to string?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can use Array.from:

Array.from(foo).join(' ')

or the spread syntax:

[...foo].join(' ')
over 4 years ago · Santiago Trujillo Denunciar

0

You can iterate through the set and build an array of the elements and return the desired string by joining the array.

var foo = new Set();
foo.add('hello');
foo.add('world');
foo.add('JavaScript');
let strArray = [];

for(str of foo){
  strArray.push(str);
}

console.log(strArray.join(" "));
over 4 years ago · Santiago Trujillo 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