-
-
Save pc035860/1e4936e074df9ed68454f8a5f6c16ec8 to your computer and use it in GitHub Desktop.
Simple, standalone, vanilla implementation of lodash.get
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Implementation of lodash.get function */ | |
| function getProp( object, keys, defaultVal ){ | |
| keys = Array.isArray( keys )? keys : keys.split('.'); | |
| object = object[keys[0]]; | |
| if( object && keys.length>1 ){ | |
| return getProp( object, keys.slice(1) ); | |
| } | |
| return object === undefined? defaultVal : object; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment