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.
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.
3) Filter - with help of filter method we easily filter some elements from array . suppose we want to take numbers only smaller than 2.
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
5) Push - It will add element at end of array.
6) Pop - It will remove last element of array.
7) Indexof - It simply gives index of given element
8) Reverse - It will reverse array.
9) Includes - If value is present in array it will give us true else false.
Top comments (0)