한번씩 읽고 가세요.
“ 지연되는 프로젝트에 인력을 더 투입하면 오히려 더 늦어진다. ”
- Frederick Philips Brooks
Mythical Man-Month 저자
728x90
오늘은 숙제가 없어 일기를 쓰기로 했다.....
오늘 오전 수업에 배운 자바 스크립트에 대해 써보려한다.
forEach, for in , for of 에 대해서 배웠다.
forEach
{
const num =[100,200,300,400,500];
document.write(num[0],"<br>")
document.write(num[1],"<br>")
document.write(num[2],"<br>")
document.write(num[3],"<br>")
document.write(num[4],"<br>")
}
//for----------------------------------------------------------
for(let i=0 ; i<num.length;i++){
document.write(num[i],"<br>")
}
//forEach------------------------------------------------------
num.forEach(function(el){
document.write(el,"<br>")
});
//forEach :화살표 함수 :----------------------------------------
num.forEach((el)=>{
document.write(el,"<br>")
});
//forEach :화살표 함수 : 괄호생략--------------------------------
num.forEach(el=>{
document.write(el,"<br>")
});
//forEach :화살표 함수 : 중괄호 생략-----------------------------
num.forEach(el => document.write(el,"<br>"));
//forEach (값, 인덱스 , 배열)------------------------------------
num.forEach(function(element, index,array){
document.write(element,"<br>");
document.write(index,"<br>");
document.write(array,"<br>");
})
forEach는 함수안에 함수가 들어간 콜백함수이다.
for of
{
const arr = [100,200,300,400,500]
for(let i of arr){
document.write(i)
}
}
for of는 배열을 뽑아낼때 사용하는 반복문이다.
for in
{
const arr = [100,200,300,400,500]
for(let i in arr){
document.write(arr[i]);
}
}
수업을 열심히 들었지만 이해가 안된다... for in 과 for of 의 차이점은 for of는 "배열"에서 for in은 "객체"에서 원하는 값을 뽑아낼 때 사용하기 라고 한다..
map()
{
const num = [100,200,300,400,500,600]
num.forEach(function(el,i,a){
console.log(el)
console.log(i)
console.log(a)
});
num.map(function(el,i,a){
console.log(el)
console.log(i)
console.log(a)
});
}
forEach와 같다라고 적어놨는데 사실 왜인지 기억도 안나고 모르겠다!
일기를 쓰면서 느낀점은 공부하러가야겠다.