이게뭘까 질문
//07 forEach()
{
const num = [100, 200 , 300, 400, 500];
//for문을 이용해서 출력....
for(let i = 0; i< num.length; i++){
document.write(num[i]);
}
document.write("<br><br>");
//forEach()를 이용해서 출력
num.forEach(function(el){
document.write(el);
});
// forEach() 3가지 인자(parameter)값
num.forEach(function(element, index, array){
document.write(element);
document.write(index);
document.write(array);
});
document.querySelector(".sample07_result").innerHTML = element + index + array
}
</script>
07. 배열 : 데이터 불러오기 : forEach()문 forEach()문은 반복되는 동작을 수행합니다.
`{ const num = [100, 200, 300, 400, 500]; const ex = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'k', 'l', 'm']; //forEach() 3가지 인자(parameter) 값 ex.forEach(function(element, index, array){ document.write(array + "의 " + index +"번째 요소 : " + element + "<br>"); });
num.forEach(function(elment){
document.write(elment);
});
}` 결과보기a,b,c,d,e,f,g,h,k,l,m의 0번째 요소 : aa,b,c,d,e,f,g,h,k,l,m의 1번째 요소 : ba,b,c,d,e,f,g,h,k,l,m의 2번째 요소 : ca,b,c,d,e,f,g,h,k,l,m의 3번째 요소 : da,b,c,d,e,f,g,h,k,l,m의 4번째 요소 : ea,b,c,d,e,f,g,h,k,l,m의 5번째 요소 : fa,b,c,d,e,f,g,h,k,l,m의 6번째 요소 : ga,b,c,d,e,f,g,h,k,l,m의 7번째 요소 : ha,b,c,d,e,f,g,h,k,l,m의 8번째 요소 : ka,b,c,d,e,f,g,h,k,l,m의 9번째 요소 : la,b,c,d,e,f,g,h,k,l,m의 10번째 요소 : m100200300400500