Hi learners, welcome to DesignWithRehana. In this article I am going to share Top 6 JavaScript Array Methods with examples and PDF. I hope these JavaScript array methods cheat-sheet will be helpful for you.
1. forEach()
This method allows a function to run for each array element. However, it does not execute on empty elements. Instead, it loops through the array items, applying the given function to each one.
Code Example
2. sort()
sort() JavaScript array method is used to sort the given array. It compares two values and returns the same array as the reference which is now a sorted array.
Code Example
3. join()
This javascript array method is used to merge all of the array’s items into a string. It also uses a comma (,) to divide the array elements. It won’t change the original array and will not generate a new array. It returns the specified array as a string, that is split by a comma (,) by default.
Code Example
const myEbooksString = myEbooks.join()
console.log(myEbooksString);
//Expected Output: true: HTML,CSS,JavaScript,Bootstrap,ReactJS
4. reverse()
It returns the same array, but the first element moves to the last position, and vice versa. The remaining elements follow the same reversed order.
Code Example
console.log(myEbooksString);
5. reduce()
This array method is used to perform operations on an array in order to get a single value. It is an iterative process.
Code Example
6. map()
This JavaScript array method iterates over an array and calls a function on each element. The function then returns a new array with modified values.
Code Example
// Expected Output: