for
for(let i =0; i < 10; i++) {
console.log(i);
}
for (let i = 10; i > 0; i--) {
console.log(i);
}
배열과 for
const names = ['멍멍이' , '야옹이' , '멍뭉이'];
for ( let i =0; i < names.length; i++) {
console.log(names[i]);
}
for of
for ( const i of [1 , 2 , 3] ) {
console.log(i);
}
while
let i=0;
while ( i < 10 ) {
console.log(i);
i++;
}
객체를 위한 반복문 for...in
const doggy = {
name : '멍멍이',
sound : '멍멍' ,
age : 2
};
console.log(Object.entries(doggy));
console.log(Object.keys(doggy));
console.log(Object.values(doggy));
const doggy = {
name: '멍멍이',
sound: '멍멍',
age: 2
};
for (let key in doggy) {
console.log(`${key}: ${doggy[key]}`);
}