- 入参:object(对象)、path(路径:string类型)
function getPropByPath(obj, path) {
let tempObj = obj;
let keyArr = path.split('.');
let i = 0;
for (; i < keyArr.length - 1; ++i) {
let key = keyArr[i];
if (key in tempObj) {
tempObj = tempObj[key];
} else {
throw new Error(`path \'${key}\' not found!`);
}
}
return {
o: tempObj,
k: keyArr[i],
v: tempObj[keyArr[i]]
};
}
over