JavaScript Looping Array Elements🚀(Thread).
1. The for loop:
for loop is used when you want to execute a block of code as long as a specified condition is true.
Syntax :
Examples:
2. for Each:
The forEach() method calls a function (a callback function) once for each array element.
Syntax :
Example:
Note:- the function takes 3 arguments:
The item value.
The item index.
The array itself.
The example below uses only the value parameter.
3. for...of:
The for...of statement creates a loop Iterating over iterable objects , invoking a custom iteration hook with statements to be executed for the value of each distinct property.
Syntax:
Example:
4. for...in:
The for...in statement loops over all of an object's enumerable properties that are keyed by strings (ignoring those keyed by Symbols), including inherited enumerable properties.
Syntax:
Example:
5. map :
The map() method will iterate through the Array elements individually and it will perform some Operations.
Operations might be: Printing, Finding the length of the String, Concatenation, etc.
The method creates a new array by performing a function on each array element
The map() method does not execute the function for array elements without values.
The map() method does not change the original array.
Example:
6. reduce()
The reduce() method runs a function on each array element to produce (reduce it to) a single value.
The reduce() method works from left to right in the array.
The reduce() method does not reduce the original array.
If you enjoyed reading this thread, please do the following:
1. Retweet the first tweet.
2. Follow me and enable notifications: @mujeeb0147.
Thank you for reading all the way through.
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.