map()
Description
The map()
method creates an Array by sequentially invoking a
function on the elements of the calling array. The new
Array elements are the value of function after each call. The
function parameter can be an anonymous Function or a top-level
object method.
The calling array isn’t changed.
Parameters
Return value
Type | Description |
---|---|
Array with the result of function invoked on each element of the calling array. |
Examples
-
Create an Array by mapping Array elements to subArrays that are constructed from the element value and the element value plus one, using an anonymous Function:
[1, 2, 3].map(x => [x, x + 1])
[ [ 1, 2 ], [ 2, 3 ], [ 3, 4 ] ]
-
Create an Array by passing a top-level object method as the mapping Function:
[{name: "D"}, {name: "E"}].map(Collection.create)
[ { name: "D", coll: Collection, ts: Time("2099-02-18T20:06:25.620Z"), indexes: {}, constraints: [] }, { name: "E", coll: Collection, ts: Time("2099-02-18T20:06:25.620Z"), indexes: {}, constraints: [] } ]
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!