Skip to main content

array.map(function)

Applies a function an array’s items, adding the results to a new array

Availability

Device + Agent

Parameters

Name Type Description
function Function A data-manipulation function

Returns

Array — a new array

Description

This method applies the supplied function to every item in the target array, one by one. The results are placed in a new array created by map() and returned by it. The new array will be the same size as the target array.

Contrast map() with apply() which changes the array’s items in situ.

The passed function must include a single parameter into which each item in the target array is passed. It is the function’s job to make sure the array values passed are appropriate to the changes it will make, if any.

Example Code