배열과 반복문을 함께 자주 사용하는 이유
var abc = ['디','스','코','딩','딩','너','무','좋','아','요'] 이라는 배열을
순서대로 출력하고 싶다.❓❗
반복문을 사용하지 않고 코드를 쓴 경우.
<!DOCTYPE html>
<html>
<head></head>
<title></title>
<meta charset="UTF-8">
<script>
var abc = ['디','스','코','딩','딩','너','무','좋','아','요']
document.write(abc[0]);
document.write(abc[1]);
document.write(abc[2]);
document.write(abc[3]);
document.write(abc[4]);
document.write(abc[5]);
document.write(abc[6]);
document.write(abc[7]);
document.write(abc[8]);
document.write(abc[9]);
</script>
</head>
<body>
</body>
</html>
for in 반복문을 사용하여 코드를 쓴 경우.
for (var [변수명] in [객체 | 배열]){
[소스 코드];
}
<html>
<head></head>
<title></title>
<meta charset="UTF-8">
<script>
var abc = ['디','스','코','딩','딩','너','무','좋','아','요']
for(var i in abc){
document.write(abc[i]);
}
</script>
</head>
<body>
</body>
</html>
ex 2) var abc = ['디','스','코','딩','딩','너','무','좋','아','요']를
뒤에부터 순서대로 삭제하기
1. 파격적인 시간 단축!✨
2. 코드의 간소화!✌
3. 🙆♂️개발자의 편리함🙆♂️