map()
Transforms each element and produces a new arr.
Syntax
arr.map(element => newValue)
Description
Runs the function you provide for each element; creates a NEW arr from the results. Does not modify the original.
Returns
New arr.
Example
Loading editor…
Expected output
[ 2, 4, 6 ]
When to use?
Transforming a list into another list (adding tax to prices, capitalizing names).