JavaScript Array method: map()
[this page | pdf | back links]
The map() method (when applied to a JavaScript
array) creates
a new array consisting of elements which are the result of calling a function
on each element of the original array in turn.
It
has the following syntax with the following parameters. It returns a new
array. It does not execute the function if array element does not have a value
and it does not change the original array.
array.map(function(currentValue, index,
arr), thisValue)
|
Parameter
|
Required / Optional
|
Description
|
|
function(currentValue,
index, arr)
|
Required
|
A function to be run
for each element
|
|
thisValue
|
Optional
|
A value to be passed to
the function to be used as its ‘this’ value (if empty then thisValue
will be undefined
|
The function
arguments are:
|
Parameter
|
Required / Optional
|
Description
|
|
currentValue
|
Required
|
The value of the
current element
|
|
Index
|
Optional
|
The array index of the
current element
|
|
arr
|
Optional
|
The array object which
the current element belongs to
|
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Arrays