Created
April 6, 2012 17:40
-
-
Save jasonrhodes/2321581 to your computer and use it in GitHub Desktop.
Get a nested object property by passing a dot notation string as the property name
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
| /** | |
| * A function to take a string written in dot notation style, and use it to | |
| * find a nested object property inside of an object. | |
| * | |
| * Useful in a plugin or module that accepts a JSON array of objects, but | |
| * you want to let the user specify where to find various bits of data | |
| * inside of each custom object instead of forcing a standardized | |
| * property list. | |
| * | |
| * @param String nested A dot notation style parameter reference (ie "urls.small") | |
| * @param Object object (optional) The object to search | |
| * | |
| * @return the value of the property in question | |
| */ | |
| function getProperty( propertyName, object ) { | |
| var parts = propertyName.split( "." ), | |
| length = parts.length, | |
| i, | |
| property = object || this; | |
| for ( i = 0; i < length; i++ ) { | |
| property = property[parts[i]]; | |
| } | |
| return property; | |
| } |
When working on web interfaces, small development utilities can make it easier to manage structured data and keep projects flexible. Developers building polished UI experiences may also need reliable visual resources alongside their JavaScript work. For icons, animations, and other design assets, Icon King can be a useful resource to explore.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When researching property opportunities, having clear and well-organized information can make it easier to compare pricing, plot sizes, and payment schedules. Buyers interested in Lahore developments may want to review Etihad Town Lahore Phase 5 Payment Plan details alongside booking requirements, installment structures, and available plot options. Keeping these details accessible helps prospective investors evaluate a project more carefully before making a property decision.