From 4bebd0e5ef9add0cc5d133aa0139a35e5c48a453 Mon Sep 17 00:00:00 2001 From: Chalarangelo Date: Tue, 28 Sep 2021 19:30:27 +0300 Subject: [PATCH] Partially reformat for loop post --- blog_posts/javascript-for-in-for-of-foreach.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/blog_posts/javascript-for-in-for-of-foreach.md b/blog_posts/javascript-for-in-for-of-foreach.md index 8c10b6c8b..27f68af5a 100644 --- a/blog_posts/javascript-for-in-for-of-foreach.md +++ b/blog_posts/javascript-for-in-for-of-foreach.md @@ -9,8 +9,7 @@ firstSeen: 2020-01-20T10:12:31+02:00 lastUpdated: 2021-06-12T19:30:41+03:00 --- -`for...in` is used to iterate over all enumerable properties of an object, including inherited enumerable properties. -This iteration statement can be used with arrays strings or plain objects, but not with `Map` or `Set` objects. +`for...in` is used to iterate over all enumerable properties of an object, including inherited enumerable properties. This iteration statement can be used with arrays strings or plain objects, but not with `Map` or `Set` objects. ```js for (let prop in ['a', 'b', 'c']) @@ -26,8 +25,7 @@ for (let prop in new Set(['a', 'b', 'a', 'd'])) console.log(prop); // undefined (no enumerable properties) ``` -`for...of` is used to iterate over iterable objects, iterating over their values instead of their properties. -This iteration statement can be used with arrays, strings, `Map` or `Set` objects, but not with plain objects. +`for...of` is used to iterate over iterable objects, iterating over their values instead of their properties. This iteration statement can be used with arrays, strings, `Map` or `Set` objects, but not with plain objects. ```js for (let val of ['a', 'b', 'c']) @@ -43,8 +41,7 @@ for (let val of new Set(['a', 'b', 'a', 'd'])) console.log(val); // a, b, d (Set values) ``` -Finally, `forEach()` is a method of the `Array` prototype, which allows you to iterate over the elements of an array. -While `forEach()` only iterates over arrays, it can access both the value and the index of each element while iterating. +Finally, `forEach()` is a method of the `Array` prototype, which allows you to iterate over the elements of an array. While `forEach()` only iterates over arrays, it can access both the value and the index of each element while iterating. ```js ['a', 'b', 'c'].forEach(