The function iterates over items in an list or tuple and returns a new list based on the results of a given callback function.
This function does not generate a change.
array.map(callback)
Argument | Type | Description |
---|---|---|
callback | closure (required) | Closure to execute on each value. |
Explanation of the callback argument:
Iterable | Arguments | Description |
---|---|---|
array | item, index | Iterate over all items in the array. Both item and index are optional. |
A new list of items that are the result of the callback function.
This code shows an example using map():
users = [{name: "Iris", age: 6}, {name: "Sasha", age: 34}];
// returns ["Iris", "Sasha"]
users.map(|user| user.name);
Return value in JSON format
[
"Iris",
"Sasha"
]