Sitemap
Aliajam

Aliajam

JavaScript Array Functions

3 min readMar 1, 2020

--

Press enter or click to view image in full size

Learn how to use map, filter, reduce, some, every, sort, and splice in JavaScript.

Map

The map() method is used for creating a new array with the same length from an existing one, applying a function to each one of the elements of the first array.

Example

Press enter or click to view image in full size

Filter

The filter() method takes each element in an array and it applies a conditional statement against it. If this conditional returns true, the element gets pushed to the output array. If the condition returns false, the element does not get pushed to the output array.

Example

Press enter or click to view image in full size

Reduce

The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value.

Example

Press enter or click to view image in full size
Press enter or click to view image in full size

Sort

The sort() method sorts the elements of an array in place and returns the sorted array.

Example

Press enter or click to view image in full size

Some

The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns a Boolean value.

Example

Press enter or click to view image in full size

Every

The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.

Example

Press enter or click to view image in full size

Splice

The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.

Syntax

Press enter or click to view image in full size

The index at which to start changing the array.

Get Aliajam’s stories in your inbox

Join Medium for free to get updates from this writer.

deleteCount is an integer indicating the number of elements in the array to remove from start. If 0 will insert new element to the array

Example

Press enter or click to view image in full size

--

--