Edit this page

up.util up.util.map(list, block)
JavaScript function

Translate all items in a list to new array of items.

Example

The given mapping function will be called for each element in the list:

up.util.map(['apple', 'cherry'], (str) => str.length) // result: [5, 6]

You can also pass a property name as a string, which will be collected from each item in the list:

up.util.map(['apple', 'cherry'], 'length') // result: [5, 6]

Parameters

list
required
ListIterator
block
required

A function that will be called with each element and (optional) iteration index.

You can also pass a property name as a string, which will be collected from each item in the list.

Function(element, index): anystring

Return value

A new array containing the result of each function call.