Skip to content

Instantly share code, notes, and snippets.

@SanthoshRaju91
Created April 26, 2018 06:28
Show Gist options
  • Save SanthoshRaju91/3d121296ca4fd5a6f08f6e0dcd660e35 to your computer and use it in GitHub Desktop.
Save SanthoshRaju91/3d121296ca4fd5a6f08f6e0dcd660e35 to your computer and use it in GitHub Desktop.
// finding value for deeply nested objects with object keys
function findKeyValue(paymentObj, key) {
const keySplit = key.split('.');
let value = '';
function findValue(obj, first, ...keys) {
if(typeof obj[first] === 'object') {
if(keys) {
findValue(obj[first], ...keys);
}
} else {
value = obj[first];
}
}
findValue(paymentObj, ...keySplit);
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment