DEV Community

abhisheks-12
abhisheks-12

Posted on

Java Script Array Methods

Array is data structure in which we store different collection of data. Now we are going to see array methods.

1) ForEach- For looping over array we use ForEach method,
it will access every element individually and it takes callback function.

Image description

2) Map - It will create new array without changing original array. Suppose we want multiply each number by two from given array and push it in new array , we can do it easily with help of map.

Image description

3) Filter - with help of filter method we easily filter some elements from array . suppose we want to take numbers only smaller than 2.

Image description

4) Reduce - Suppose we have array which contains number and we want sum of those numbers. Here we can use reduce method which takes call back function and accumulator. We add accumulator and current number and at end of loop it takes accumulators value

Image description

5) Push - It will add element at end of array.

Image description

6) Pop - It will remove last element of array.

Image description

7) Indexof - It simply gives index of given element
Image description

8) Reverse - It will reverse array.
Image description

9) Includes - If value is present in array it will give us true else false.

Image description

10) Join - It will join array and convert it into string
Image description

Top comments (0)