Last active
November 4, 2020 01:32
-
-
Save jerlyrosa/7efebd927eface82f21437f6447f4aac to your computer and use it in GitHub Desktop.
Tipo de dato Set en javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// El objeto Set permite almacenar valores únicos de cualquier tipo, incluso valores primitivos u referencias a objetos. | |
let set = new Set([1,2,3,3,4,4,5]) | |
console.log(set); | |
// Metodo .add() nos ayuda agregar nuevos datos a nustros Sets | |
set.add(7); | |
set.add(6); | |
set.add(6); | |
set.add(6); | |
set.add(8); | |
//Iteradores para set | |
console.info('Primer iterador "For of"'); | |
for (const iterador of set) { | |
console.log(iterador); | |
} | |
console.info('Segundo iterador "forEach"'); | |
set.forEach(element => console.log(element)); | |
//Metodo .has() comprueba si existe ese valor | |
console.log(set.has(10)); | |
//Metodo .delete() borra el valor que le pasemos | |
console.log(set.delete(2)); | |
//Metodo .size nos dice el tamaño de nuestro sets | |
console.log(set.size); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment