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

You might not need React Context

React Context vs HOCs

A simple trick to turn Express validators conditional

Scaling your services: Understanding the Service Discovery and Service Mesh

How to make Responsive Designs in React Native

React Hooks: useReducer

#100DaysOfCode: Day 7

Dependency management for Ionic/Angular app

Understanding React Concurrent Mode: Part 2

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

Promises in Javascript

Advance Objects: JavaScript

Introduction to JavaScript

JavaScript Variable Keywords