1. 背景 我们有时需要从嵌套结构获取对应的数据,比如以下结构: const nested = { a: { b: { c: 10, }, }, }; 通过a.b.c读取,但如果某个字段的值可能为空,会导致报错 我们可以实现一个getDeepObjByKeys方法去解决 getDeepObjByKeys(data,path,defaultValue) getDeepObjByKeys(nested,"a.b.d","defaultValue") // 读...

Markdown supported · ⌘↵ to post
No responses yet.