Skip to content

Instantly share code, notes, and snippets.

@ilhamgusti
Created February 19, 2021 08:49
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 ilhamgusti/83bed418013bf0fd2eae8023ed47e9bb to your computer and use it in GitHub Desktop.
Save ilhamgusti/83bed418013bf0fd2eae8023ed47e9bb to your computer and use it in GitHub Desktop.
javascript string dot notation into object reference
function index(obj,is, value) {
if (typeof is == 'string')
return index(obj,is.split('.'), value);
else if (is.length==1 && value!==undefined)
return obj[is[0]] = value;
else if (is.length==0)
return obj;
else
return index(obj[is[0]],is.slice(1), value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment