Policies & Guidelines

PLUCK

Get a property of each object in an array

Description

Gets the values for each object in the given array by the given key, and returns an array with those values, in the corresponding order.

For example, if you have an array of people as objects, you can get the name of each person by providing the array as the first parameter, and the key name "name" as the second parameter.

Function signature

PLUCK(array: Array, key: String) => Array

Parameter

Description

Array

Array of objects whose properties to get

Key

Name of the key whose value to take from each object

Examples

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

Formula

Return value

PLUCK(products, "price")

[5,60]

PLUCK(animals, "name")

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