You-Dont-Need-Lodash-Underscore
You-Dont-Need-Lodash-Underscore copied to clipboard
_.get implementation
I would like to confirm the documentation, it says if the path in the object isn't found it will result in object error. I want to clarify is not the whole point of _.get to search the unknown and paths may not exist? https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get
You're right about this one. The implementation shown doesn't match the features of _.get
- path can be a string OR array of strings
- returns
undefined
if object doesn't contain path/property - can return a default value if path doesn't exist
var object = { 'a': [{ 'b': { 'c': 3 } }] };
_.get(object, 'a[0].b.c');
// => 3
_.get(object, ['a', '0', 'b', 'c']);
// => 3
_.get(object, 'a.b.c', 'default');
// => 'default'