Given a deep-search query path, returns an object property or array value of an object or array.
const obj = { foo: { bar: ['baz'] } };const value = get(obj, 'foo.bar[0]');// type of value -> unknown; value === 'baz'const value = get(obj, 'foo.bar.nothing', 'default');// type of value -> unknown; value === 'default'const value = get(obj, 'foo["bar"][0]');// type of value -> unknown; value === 'baz'const arr = [obj];const value = get(arr, '[0].foo.bar[0]');// type of value -> unknown; value === 'baz' Copy
const obj = { foo: { bar: ['baz'] } };const value = get(obj, 'foo.bar[0]');// type of value -> unknown; value === 'baz'const value = get(obj, 'foo.bar.nothing', 'default');// type of value -> unknown; value === 'default'const value = get(obj, 'foo["bar"][0]');// type of value -> unknown; value === 'baz'const arr = [obj];const value = get(arr, '[0].foo.bar[0]');// type of value -> unknown; value === 'baz'
Any value to query.
The query path.
Optional
The default to return if the query result was not defined.
Given a deep-search query path, returns an object property or array value of an object or array.