Skip to content

Instantly share code, notes, and snippets.

@ratiw
Last active May 15, 2019 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ratiw/55edd04b9cacbef6ff84 to your computer and use it in GitHub Desktop.
Save ratiw/55edd04b9cacbef6ff84 to your computer and use it in GitHub Desktop.
Retrieve object property using dot notation. Equivalent to Laravel's object_get()
function object_get(obj, key) {
if (!key || $.trim(key) == '') return obj;
$.each(key.split('.'), function(idx, seg) {
if (typeof obj !== 'object' || obj[seg] === undefined) {
obj = undefined;
return obj;
}
obj = obj[seg];
});
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment