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 is used to call a function for each array element. However, this method will not be executed on empty elements. This method iterates through the items of an array, executing the input function for each element.
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()
This array function reverses the given array. It returns the same array, but the first element becomes the last and the last element becomes the first. Similarly, additional array elements turned in the other direction.
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 across an array. It calls the method for each array element. And for each array element, it produces a new array by invoking a certain procedure.
Code Example
// Expected Output: