Skip to content

Instantly share code, notes, and snippets.

@Smidgens
Created July 23, 2020 13:04
Show Gist options
  • Save Smidgens/06fab5e14305f409f16c8d376cc05807 to your computer and use it in GitHub Desktop.
Save Smidgens/06fab5e14305f409f16c8d376cc05807 to your computer and use it in GitHub Desktop.
Retrieves an object property at a given path (prop.subprop.subsubprop etc.)
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