-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforEach.html
More file actions
36 lines (31 loc) · 810 Bytes
/
Copy pathforEach.html
File metadata and controls
36 lines (31 loc) · 810 Bytes
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>자바스크립트 forEach문</title>
<script type="text/javascript">
//배열 선언 초기화
var fruits = ["사과", "포도", "복숭아"];
//1. item
fruits.forEach(function(item){
document.write(item+"<br>");
});
document.write("<hr>");
//2. item, index
fruits.forEach(function(item, index){
document.write(index + " " + item+"<br>");
});
document.write("<hr>");
//3. item, index, fruits
fruits.forEach(function(item, index, fruits){
document.write(index + " " + item +" "+ fruits+ "<br>");
});
//4. console에서
fruits.forEach(function(item, index, fruits){
console.log(index, item, fruits);
});
</script>
</head>
<body>
</body>
</html>