JavaScript Simple Array Iterators

.forEach()

The .forEach() method executes a callback function on each of the elements in an array in order. The callback function containing a console.log(number) method will be executed 3 times, once for each element. After it will each number in the array.

.map()

The .map() method executes a callback function on each element in an array. It returns a new array made up of the return values from the callback function. The original array does not get altered, and the returned array may contain different elements than the original array.

.reduce()

The .reduce() method iterates through an array and returns a single value. It takes a callback function with two parameters accumulator and currentValue as arguments. On each iteration, accumulator is the value returned by the last iteration, and the currentValue is the current element. The .reduce() will sum all the elements of the array and return 100 after it is executes.

.filter()

The .filter() method executes a callback function on each element in an array. The callback function for each of the elements must return either true or false . The returned array is a new array with any elements for which the callback function returns true. The array filtered will contain all the elements of the numbers array except 4 since only numbers greater than 5 are filtered out.

For more information on JavaScript iterations

--

--

--

Currently Studying to be a Software Engineer At Flatiron.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to build a Dialogflow bot using Hasura

How Magento 2 generates javascript translations during static content deploy

Bookmarks with Javascript

React — Lifecycle + Pure Components — Part-5

React Native Tutorial Step 38 — Styling the Search Results

6 Steps to making Magento fast!

Story extends Blog

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akram Alam

Akram Alam

Currently Studying to be a Software Engineer At Flatiron.

More from Medium

Why JavaScript Promises are awesome

Create and Print Linked List in JavaScript

ES6 Key Features Every JavaScript Developer Must Know

Essential JavaScript Functional Programming Concepts for React