Created
September 29, 2018 23:23
-
-
Save Yaob1990/851a2741c0f71fa332e427943cf2c996 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
| function getObjectVal(obj, keyArray, index) { | |
| if (!Object.prototype.toString.call(obj) === "[object Array]") return null; | |
| if (!keyArray) return null; | |
| if (arguments.length === 2) { | |
| return getObjectVal(obj, keyArray, 0); | |
| } | |
| var key = keyArray[index]; | |
| if (keyArray.length - index === 1) { | |
| if (!key) return null; | |
| return obj[key]; | |
| } | |
| if (!key) return null; | |
| if (!obj[key]) return null; | |
| return getObjectValByKeyArr(obj[key], keyArray, index + 1); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment