DEV Community

Akash
Akash

Posted on

JavaScript Array Iterations Methods

*Array Iteration Methods can be classified into following types

1.Array forEach

  • forEach () calls a function once for each array element. (e.g)


OUTPUT:
0
1
2
3
4
Here Callback function runs 5 times(for each value function runs)to execute code.

2.Array map()

  • Map() creates new array by callback function without replacing original array it clones the array
  • Map() returns value (e.g)


OUTPUT:[30,9,15,21,18]

3.Array flat map()

  • flat map() is used to expanding elements ,maps all elements of array and creates new array (e.g)


OUTPUT:[1,10,2,20,3,30,4,40,5,50]

4.Array filter()

  • filter() used to create new array by passing test by condition . (e.g)


OUTPUT:[50,48,70]

5.Array reduce()

  • reduce() used to produce single value by running each elements in array
  • It runs from left to right. (e.g)


OUTPUT:31

6.Array reduceRight()

  • reduceRight() is also used to produce single value by running every elements in array
  • Only difference is it runs from right to left
  • Looks similar to reduce() (e.g)


OUTPUT:30

7.Array every()

  • every() checks if all array elements get pass
  • If even single element get fail the result get false. (e.g)  OUTPUT: False

8.Array some()

  • Some() checks if some array value get pass
  • If even a single element get pass result is true (e.g)


OUTPUT: TRUE

9.Array.from()

  • Array.from() used to convert from string to array (e.g)


OUTPUT:['A','K','A','S','H']

10.ArraySpread()

  • spread() used to combine two different array (e.g)


OUTPUT: [1,2,3,4,5,6]

*11. ArrayRest()
*
*Rest() is used to collect remaining elements of array into nee array
(e.g)


OUTPUT:[3,4,5]

12.Arraywith()

  • with() used to update elements in array without changing the original array. (e.g)


OUTPUT: [ 'Akash', 'mani', 'surya', 'sharma']

*13.Array keys() [Tbd]
14.Array entries() [Tbd]
*

Top comments (0)