Skip to content

Instantly share code, notes, and snippets.

@linus-amg
Created Nov 5, 2015
Embed
What would you like to do?
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