Gets the data at path in object. Assumes '.' separates each segment of path.
path
object
getField({ name: { first: `Thom`, last: `Yorke` }}, `name.first`); // { value: `Thom` success: true }getField({ colours: [`red`, `green`, `blue` ]}, `colours.1`); // { value: `green` success: true } Copy
getField({ name: { first: `Thom`, last: `Yorke` }}, `name.first`); // { value: `Thom` success: true }getField({ colours: [`red`, `green`, `blue` ]}, `colours.1`); // { value: `green` success: true }
Returns an error result with more details, eg { success: false, error: 'Path could not be found' }
{ success: false, error: 'Path could not be found' }
Throws if:
Object to query
Path
Separator of chunks of path. Defaults to '.'
Gets the data at
pathinobject. Assumes '.' separates each segment of path.Returns an error result with more details, eg
{ success: false, error: 'Path could not be found' }Throws if:
pathis not a string or emptyobjectis undefined or null