|
|
|
@ -151,7 +151,7 @@ do {
|
|
|
|
|
|
|
|
|
|
### for of loop
|
|
|
|
|
|
|
|
|
|
We use for of loop for arrays. It is very hand way to iterate through an array if we are not interested in the index of each element in the array.
|
|
|
|
|
We use for of loop for arrays. It is very handy way to iterate through an array if we are not interested in the index of each element in the array.
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
for (const element of arr) {
|
|
|
|
@ -180,7 +180,7 @@ let sum = 0
|
|
|
|
|
for (const num of numbers) {
|
|
|
|
|
sum = sum + num
|
|
|
|
|
// can be also shorten like this, sum += num
|
|
|
|
|
// after this we will use the shorter synthax(+=, -=, *=, /= etc)
|
|
|
|
|
// after this we will use the shorter syntax(+=, -=, *=, /= etc)
|
|
|
|
|
}
|
|
|
|
|
console.log(sum) // 15
|
|
|
|
|
|
|
|
|
|