Skip to content

Instantly share code, notes, and snippets.

@linus-amg
Created November 5, 2015 19:03
Show Gist options
  • Save linus-amg/c5448b89683d2f382035 to your computer and use it in GitHub Desktop.
Save linus-amg/c5448b89683d2f382035 to your computer and use it in GitHub Desktop.
ref
function ref(obj, str) {
str = str.split(".");
for (var i = 0; i < str.length; i++)
obj = obj[str[i]];
return obj;
}
var obj = { a: { b: 1, c : { d : 3, e : 4}, f: 5 } }
str = 'a.c.d'
ref(obj, str) // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment