DEV Community

Cristian Fernando
Cristian Fernando

Posted on

4 1

Paracetamol.js💊| #110: Explica este código JavaScript

Explica este código JavaScript

Dificultad: Básico

const set = new Set([1,2,1,5,9,5,0]);
for(let item of set){
  console.log(item)
}
Enter fullscreen mode Exit fullscreen mode

A. 1,2,1,5,9,5,0
B. 1 2 5 9 0
C. SyntaxisError
D. Ninguna de las anteriores

Respuesta en el primer comentario.


Respuesta:
B. 1 2 5 9 0

Para poder iterar sobre objetos Set podemos usar un ciclo for...of que recorrerá cada item del nuestro Set obviamente omitiendo los elementos repetidos.

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay