Created
April 26, 2018 06:28
-
-
Save SanthoshRaju91/3d121296ca4fd5a6f08f6e0dcd660e35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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