Handlebar Helper Function: Map

Extracts a specific field from each object in a list, returning a list of those field values. It supports both simple arrays and complex object structures.

ParameterTypeDescription
listarrayRequired. The list of objects to map.
fieldNamestringRequired. The field to extract from each object. If the field doesn’t exist in an object, that object is skipped.

The function returns a new list containing the values of the specified field from each object in the input list. If the specified field isn’t present in an object, that object is skipped. If a parameter is missing or an element in the list isn’t a valid map, the function throws an exception.

This example shows how to use the map function to extract the age field from each object in the list.

The function returns [30, 25].

You can chain the map function with other functions such as filter, sort, and flatten.

The function returns ["Miguel", "Lakshmi"].

With complex nested objects, use the flatten function to flatten the nested objects before you map the values, as shown in this example.

The function returns [100, 200, 300].