实现
1const a = {2 b: {3 c: [1, 2, 3],4 },5};67const get = (obj, path, defaultValue = undefined) => {8 if (path.length === 0) {9 return obj;10 }11 if (!obj) {12 return defaultValue;13 }14 if (typeof path === "string") {15 path = path.replace(/\[/g, ".").replace(/\]/g, "").split(".");16 }17 let p = path.shift();18 return get(obj[p], path);19};2021const res = get(a, "b.c[3]");2223console.log(res);