-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfor...of.js
More file actions
82 lines (58 loc) · 1.03 KB
/
for...of.js
File metadata and controls
82 lines (58 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Sintaxis
for ( variable of iterable ) {
// Código ...
}
// Ejemplo 01
// const
const frutas = ["🍎", "🍊", "🍓", "🍇", "🍌"];
for(const fruta of frutas) {
console.log(fruta);
}
// 🍎
// 🍊
// 🍓
// 🍇
// 🍌
// let
const animales = ["🐓", "🐈", "🐄", "🐠", "🦀"];
for (let animal of animales) {
animal += animal;
console.log(animal);
}
// 🐓🐓
// 🐈🐈
// 🐄🐄
// 🐠🐠
// 🦀🦀
// Ejemplo 02
let palabra = "Hola";
for(let letra of palabra) {
console.log(letra.toUpperCase());
}
// H
// O
// L
// A
// Ejemplo 03
function imprimirArguments() {
for(let argumento of arguments) {
console.log(argumento);
}
}
imprimirArguments("1️⃣", "2️⃣", "3️⃣", "4️⃣");
// 1️⃣
// 2️⃣
// 3️⃣
// 4️⃣
// Ejemplo 04
const imagenes = document.querySelectorAll("img");
for(let imagen of imagenes) {
imagen.classList.add("lazy");
}
console.log(imagenes);
/*
NodeList(2) [img.lazy, img.logo.lazy]
length: 2
0: img.lazy
1: img.logo.lazy
*/