Last active
January 28, 2021 15:40
-
-
Save rap0so/392a6c8bfb8f8ea92baca6bf891e5645 to your computer and use it in GitHub Desktop.
This function is a improved way of loadash lib
This file contains 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
/** | |
* _Get function is a copy of a method of loadash lib | |
* that get `property` of `object` testing all nested properties if needs it | |
* | |
* @param {object} obj | |
* @param {string} key | |
* | |
*/ | |
function _get(object, keys, defaultVal) { | |
keys = Array.isArray(keys) ? keys : keys.split('.') | |
object = object[keys[0]] | |
if (object && keys.length > 1) { | |
return _get(object, keys.slice(1), defaultVal) | |
} | |
return !object ? defaultVal : object | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
put a try ctach to avoid disorders
``
function _get(object, keys, defaultVal) {
keys = Array.isArray(keys) ? keys : keys.split('.')
}
``