Widely availableSupported across all major browsers. Safe to use in production.

Overview

Array iteration methods

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
1
12
1.5
3
18
1
Built-in object

The filter() method of Array instances creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.

1
12
1.5
3
18
1

The forEach() method of Array instances executes a provided function once for each array element.

1
12
1.5
3
18
1

The indexOf() method of Array instances returns the first index at which a given element can be found in the array, or -1 if it is not present.

1
12
1.5
3
18
1

The lastIndexOf() method of Array instances returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.

1
12
1.5
3
18
1

The map() method of Array instances creates a new array populated with the results of calling a provided function on every element in the calling array.

1
12
1.5
3
18
1

The reduce() method of Array instances executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.

3
12
3
4
18
3.2

The reduceRight() method of Array instances applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value.

3
12
3
4
18
3.2

The some() method of Array instances returns true if it finds an element in the array that satisfies the provided testing function. Otherwise, it returns false.

1
12
1.5
3
18
1
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
const nums = [1, 2, 3, 4, 5];

nums.map(n => n * 2);        // [2, 4, 6, 8, 10]
nums.filter(n => n > 3);     // [4, 5]
nums.reduce((a, b) => a + b); // 15
nums.some(n => n > 4);       // true
nums.every(n => n > 0);      // true

Live demo

Value Convert with map

Array. eachelement 2 to newarray create..

PreviewFullscreen

condition clip with filter

3 than bignumberonly extract..

PreviewFullscreen

all itemscheck with every

all. Element that 0 than big or inspect it..

PreviewFullscreen

Use cases

  • Using Array iteration methods

    Array iteration methods

Cautions

  • No specific concerns. Stable across all major browsers.

Accessibility

  • When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.

Powered by web-features