For...of Loops

๐Ÿ‘จโ€๐Ÿ’ผ When you want to iterate over an array and just need each value (not the index), for...of provides clean, readable syntax.
The syntax:
for (const item of array) {
	// use item
}
For example:
const fruits = ['apple', 'banana', 'cherry']
for (const fruit of fruits) {
	console.log(fruit)
}
// Logs: apple, banana, cherry
๐Ÿจ Open and:
  1. Create an array colors with at least 4 colors
  2. Use for...of to log each color
  3. Create an array numbers with values [10, 20, 30, 40, 50]
  4. Use for...of to calculate and log the sum of all numbers
  5. Use for...of to find and log the largest number
๐Ÿ’ฐ You can also use for...of with strings to iterate over characters:
for (const char of 'hello') {
	console.log(char) // h, e, l, l, o
}

Please set the playground first

Loading "For...of Loops"
Loading "For...of Loops"
Login to get access to the exclusive discord channel.