for 문 & continue
for (let i = 9; i > -1; i--) {
if (i % 2 === 0) {
continue
}
console.log(i);
}
for of 반복문
for (const 변수 of 반복하고자 하는 "배열" 데이터) {
}
const fruits = ['Apple', 'Banana', 'Cherry']
for (const fruit of fruits) {
console.log(fruit)
}
const users = [
{
name: 'Ju',
age: 22
},
{
name: 'Neo',
age: 45
},
{
name: 'Lisa',
age: 56
}
]
for (let i = 0; i <users.length; i++) {
console.log(users[i]);
console.log(users[i].name);
}
for (const user of users) {
console.log(user);
console.log(user.name);
}
for in 문
for (const key in "객체" 데이터) {
}
const user = {
name: 'Lisa',
age: 56,
inValid: true,
email: 'juuh.yung5@gmail.com'
}
for (const key in user) {
console.log(key);
console.log(user[key]);
}
console.log(user.name);
console.log(user.age);
console.log(user['name']);