Created
July 23, 2020 13:04
-
-
Save Smidgens/06fab5e14305f409f16c8d376cc05807 to your computer and use it in GitHub Desktop.
Retrieves an object property at a given path (prop.subprop.subsubprop etc.)
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
export const getDeepObjectProperty = function(ob, path, defaultValue){ | |
let segments = path.split('.'); | |
for (var i=0, len = segments.length; i < len; i++){ | |
if(!ob){ | |
return defaultValue; | |
} | |
ob = ob[segments[i]]; | |
}; | |
return ob; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment