Skip to content

Instantly share code, notes, and snippets.

@et4891
Created December 10, 2018 20:14
Show Gist options
  • Save et4891/f10c42995a3f56b94abc3d15b70ebf04 to your computer and use it in GitHub Desktop.
Save et4891/f10c42995a3f56b94abc3d15b70ebf04 to your computer and use it in GitHub Desktop.
Get nested object property using dot notation
/*
* Get nested object property using dot notation
* */
const getProperty = ( propertyName, object ) => {
let parts = propertyName.split( "." ),
length = parts.length,
i,
property = object || this;
for ( i = 0; i < length; i++ ) {
property = property[parts[i]];
}
return property;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment