MAP

Transforms each item in the array to another

Description

Goes through each item in the given array and evaluates an formula for each of them. Returns an array with the evaluated values.

The returned array has the same length than the original array, and the order of its items correspond the order in the original array.

Function signature

MAP(array: Array, transformformula: Function) => Array

Parameter

Description

Array

Array of items to transform

Transform formula

Formula to be evaluated for each item

Examples

animals = [
{
"name": "dog",
"weight": 123
},
{
"name": "cat",
"weight": 48
},
{
"name": "rat",
"weight": 10
}
]
products = [{"name":"Duct tape","price":5},{"name":"Swiss army knife","price":60}]

Formula

Return value

MAP(animals, item.name)

["dog","cat","rat"]

MAP(products, index + ": " + item.name)

["0: Duct tape","1: Swiss army knife"]

MAP<product>(products, product.name + " (" + product.price + "€)")

["Duct tape (5€)","Swiss army knife (60€)"]

MAP<product, position>(products, position + ": " + product.name + " (" + product.price + "€)")

["0: Duct tape (5€)","1: Swiss army knife (60€)"]