You-Dont-Need-Lodash-Underscore icon indicating copy to clipboard operation
You-Dont-Need-Lodash-Underscore copied to clipboard

_.get implementation

Open gregpalaci opened this issue 3 years ago • 1 comments

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

gregpalaci avatar Apr 23 '21 18:04 gregpalaci

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'

briancodes avatar May 10 '22 11:05 briancodes