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.
• • •
Missing some Tweet in this thread? You can try to
force a refresh
JavaScript Arrays🤩, Mega thread🚀.
All of the content includes examples so that any aspiring Web developer can quickly grasp the concepts.
1. What is a JavaScript Arrays.
An array in JavaScript is a variable that can hold several values.
Example:
2. What's the Point of Using an Array?
If you have a list of items (say, a list of car names), storing the cars in single variables might look like this:
Example: