We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get nested property from an Object:
f(null, _) = null f(a, []) = a f(a, x:xs) = f(a[x], xs)
function getProp(obj, propStr) { const arr = propStr.split("."); function get(obj, propArr) { if (obj == null) { return null; } else if (propArr.length === 0) { return obj; } else { const head = propArr[0]; const tail = propArr.slice(1); return get(obj[head], tail); } } return get(obj, arr); } // Usage: const obj = { a: { b: 1 } }; console.log(getProp(obj, "a.b"));
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Get nested property from an Object:
The text was updated successfully, but these errors were encountered: