Skip to content

get

Get any attribute or child attribute using a deep path

190 bytes

Usage

Given any value and a select function to get the desired attribute, returns the desired value or a default value if the desired value couldn’t be found.

import * as _ from 'radashi'
const fish = {
name: 'Bass',
weight: 8,
sizes: [
{
maturity: 'adult',
range: [7, 18],
unit: 'inches',
},
],
}
_.get(fish, 'sizes[0].range[1]') // 18
_.get(fish, 'sizes.0.range.1') // 18
_.get(fish, 'foo', 'default') // 'default'