-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforeach.html
More file actions
55 lines (38 loc) · 1.12 KB
/
foreach.html
File metadata and controls
55 lines (38 loc) · 1.12 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Foreach</title>
<script>
/*
var listaFuncionarios = ['Viviane', 'Rosângela', 'Miguel', 'Lucas', 'Fernanda']
console.log(listaFuncionarios)
document.write(listaFuncionarios[3])
listaFuncionarios.forEach(function(valor, indice, array) {
//lógica
console.log('índice: ' + indice + ' | valor: ' + valor)
if(valor == 'Lucas') {
array[indice] = 'Um novo valor'
}
})
console.log(listaFuncionarios)
document.write('<br />' + listaFuncionarios[3])
*/
var listaFuncionarios = ['Viviane', 'Rosângela', 'Miguel', 'Lucas', 'Fernanda']
var lista_frutas = Array()
lista_frutas['x'] = 'Banana'
lista_frutas[false] = 'Maçã'
lista_frutas [27] = 'Morango'
lista_frutas[3] = 'Uva'
lista_frutas[-12] = 'Melão'
var f = function(valor, indice) {
console.log(valor, indice)
}
listaFuncionarios.forEach(f)
lista_frutas.forEach(f)
//forEach atua somente sobre valores numéricos partindo de 0
</script>
</head>
<body>
</body>
</html>