const sunnyArray = [
'Sunny',
'Ryu',
2022 - 1988,
'technical writer',
['Writing', 'Coding', 'Learning']
];
for (let i = 0; i < sunnyArray.length; i++) {
console.log(sunnyArray[i]);
}
console.log(sunnyArray[i], typeof sunnyArray[i]);
const types = [];
for (let i = 0; i < sunnyArray.length; i++) {
// Reading from sunny array
console.log(sunnyArray[i], typeof sunnyArray[i]);
// Filling types array
// types.push(typeof sunnyArray[i]);
types[i] = typeof sunnyArray[i];
}
console.log(types);
// prints (5) ['string', 'string', 'number', 'string', 'object']
const years = [1991, 1992, 1993, 1994];
const ages = [];
for (let i = 0; i < years.length; i++) {
ages.push(2037 - years[i]);
}
console.log(ages);
Continue vs. Break
The continue statement (with or without a label reference) can only be used to skip one loop iteration. The break statement, without a label reference, can only be used to jump out of a loop or a switch.
// continue and break
console.log('---ONLY STRINGS')
for (let i = 0; i < sunnyArray.length; i++) {
if (typeof sunnyArray[i] !== 'string') continue;
console.log(sunnyArray[i], typeof sunnyArray[i]);
}
https://www.w3schools.com/js/js_break.asp
'Programming > JavaScript' 카테고리의 다른 글
Looping Backwards and Loops in Loops (0) | 2022.09.19 |
---|---|
The while Loop (0) | 2022.09.19 |
Iteration: The for Loop (0) | 2022.09.15 |
Coding Challenge #3 - comparing BMIs using objects (0) | 2022.09.15 |
Object Methods (0) | 2022.09.15 |