const _get = (object, path, defaultValue = undefined) => {
const pathArray = Array.isArray(path) ? path : path.split('.')
let result = object
pathArray.forEach((element) => {
const key = element
if (result == null || !(key in result)) {
return defaultValue
}
result = result[key]
})
return result
}
lodash._get方法(简单实现思路)
最新推荐文章于 2024-07-04 20:14:22 发布