getValueByPath
liz-q 2020/12/28
根据属性字符串从对象中取值
getValueByPath(obj, prop)
# 参数
obj
(Object) :对象数据prop
(String):属性路径字符串
# 返回值
(any|undefined):查找的结果
# 例子
import { getValueByPath } from '@liz-q/utils'
const obj = {
a: {
b: {
c: 1
}
},
d: 2
}
getValueByPath(obj, 'd') // 2
getValueByPath(obj, 'a.b.c') // 1
getValueByPath(obj, 'a.b')
// {
// c: 1
// }