Pass in an array of objects and specify one or more keys to extract. The function returns a new array containing the extracted values (as an array of arrays). The input array is never mutated.
Extracts values from an array of objects based on specified
mappings. Useful for extracting multiple properties from an array
of objects (e.g. for tabular data). Also supports “computed
properties” via mapping functions, which can combine and transform
values on-the-fly.
If mappings are provided, returns an array of arrays where each
inner array contains the values extracted by applying each
mapping to the corresponding object.
If no mappings are provided, returns an array of arrays
containing all values of each object.
Extracts values from an array of objects based on specified
mappings. Useful for extracting multiple properties from an array
of objects (e.g. for tabular data). Also supports “computed
properties” via mapping functions, which can combine and transform
values on-the-fly.
If mappings are provided, returns an array of arrays where each
inner array contains the values extracted by applying each
mapping to the corresponding object.
If no mappings are provided, returns an array of arrays
containing all values of each object.
Extracts values from an array of objects based on specified
mappings. Useful for extracting multiple properties from an array
of objects (e.g. for tabular data). Also supports “computed
properties” via mapping functions, which can combine and transform
values on-the-fly.
If mappings are provided, returns an array of arrays where each
inner array contains the values extracted by applying each
mapping to the corresponding object.
If no mappings are provided, returns an array of arrays
containing all values of each object.
The pluck function can also accept mapping functions in addition to property names.
import*as
import _
_from'radashi'
const
constgods: {
name:string;
power:number;
domain:string;
}[]
gods= [
{
name: string
name: 'Ra',
power: number
power: 100,
domain: string
domain: 'Sun' },
{
name: string
name: 'Zeus',
power: number
power: 98,
domain: string
domain: 'Lightning' },
{
name: string
name: 'Loki',
power: number
power: 72,
domain: string
domain: 'Tricks' },
]
const
constmapped: (string|number)[]
mapped=
import _
_.
functionpluck<{
name:string;
power:number;
domain:string;
}, ((god: {
name:string;
power:number;
domain:string;
}) =>string) | ((god: {
name:string;
power:number;
domain:string;
}) =>number)>(array:readonly {
name:string;
power:number;
domain:string;
}[], mappings:readonly (((god: {
name:string;
power:number;
domain:string;
}) =>string) | ((god: {
name:string;
power:number;
domain:string;
}) =>number))[]): (string|number)[] (+1overload)
Extracts values from an array of objects based on specified
mappings. Useful for extracting multiple properties from an array
of objects (e.g. for tabular data). Also supports “computed
properties” via mapping functions, which can combine and transform
values on-the-fly.
If mappings are provided, returns an array of arrays where each
inner array contains the values extracted by applying each
mapping to the corresponding object.
If no mappings are provided, returns an array of arrays
containing all values of each object.