Day 12 of 30 of JavaScript
Tags: webdev, javascript, beginners, tutorial
Published: 2024-05-23 07:22:03

Hey there. Hope you are doing well😊
In the last post we have studied about the searching and sorting methods used in array. In this post we are going to discuss about **Iteration Methods** used in array.
So let's get started🔥

## Iteration Methods

Array iteration methods are functions or techniques used to traverse through each element of an array or collection of elements systematically. These methods are commonly used to perform operations on each element of an array without needing to manually write loops.

**`Array.forEach()` Method**

The `forEach()` method calls a function (a callback function) once for each array element.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r4n7j5py9xomohe4w6rx.png)
So here you can see that the `print` function is called for every element present in array.
This callback function used here uses three arguments -:

- value

- index

- array
But these are optional we can provide arguments according to our need.

**`Array.map()` Method**

Creates a new array populated with the results of calling a provided function on every element in the calling array.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9dfzb2h9qqq8h1c7ogds.png)
The callback function defined here can accept three arguments-: value, index, array.

**`Array.filter()` Method**

Creates a new array with all elements that pass the test implemented by the provided function.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9nmjww566iglvug898wr.png)
The callback function defined here can accept three arguments-: value, index, array.

**`Array.reduce()` Method**

The `reduce()` method runs a function on each array element to produce (reduce it to) a single value.
The `reduce()` method works from left-to-right in the array.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qn11hylob0cdybyea3fp.png)
Here the accumulator and currentValue are initialized to 0, accumulator stores the total sum and currentValue is initial value of accumulator.
We have `reduceRight()` which works similar to `reduce()` but works from right to left.

**`Array.every()` Method**

Tests whether all elements in the array pass the test implemented by the provided function.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/egb6g1k7plc1zznpgw2e.png)

**`Array.some()` Method**

Tests whether at least one element in the array passes the test implemented by the provided function.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/29wr2vh7e6m92nwh27cw.png)

**Array Spread (...)** 

The` ...` operator expands an iterable (like an array) into more elements.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szbceljyn4m33zo12mia.png)
The spread operator provides a concise and flexible way to work with iterables, making code more readable and allowing for cleaner syntax in various situations.

These methods explained above are very important methods. They are most commonly used methods.
I hope you have understood this blog. In the upcoming blogs we are going to read about OOPs. Till then stay connected and don't forget to follow me.🤍