Last active
March 17, 2016 07:01
-
-
Save think2011/b44726f386eadd111f56 to your computer and use it in GitHub Desktop.
根据obj的path获得数据
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
/** | |
* 根据obj的path获得数据 | |
* @param obj {Object} | |
* @param path {String} | |
* @returns {*} | |
*/ | |
function getValueOfPath(obj, path) { | |
var pathArray = path.split('.') | |
var currentPath = pathArray.shift() | |
if (obj[currentPath] && pathArray.length) { | |
return getValueOfPath(obj[currentPath], pathArray.join('.')) | |
} else { | |
return obj[currentPath] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment