Created
December 10, 2018 20:14
-
-
Save et4891/f10c42995a3f56b94abc3d15b70ebf04 to your computer and use it in GitHub Desktop.
Get nested object property using dot notation
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
/* | |
* 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