Skip to content

Instantly share code, notes, and snippets.

@think2011
Last active March 17, 2016 07:01
Show Gist options
  • Save think2011/b44726f386eadd111f56 to your computer and use it in GitHub Desktop.
Save think2011/b44726f386eadd111f56 to your computer and use it in GitHub Desktop.
根据obj的path获得数据
/**
* 根据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