当前位置:网站首页>链式长取值
链式长取值
2022-07-03 07:49:00 【ange2017】
分享一个链式长取值的function ,代替可选链 。
// 链式长取值
get(source, path, defaultValue = undefined) {
const paths = path.replace(/\[(\d+)\]/g, '.$1').split('.')
let result = source
for (const p of paths) {
result = Object(result)[p]
if (result === undefined) {
return defaultValue
}
}
return result
},
边栏推荐
- How to clear the console password for s7700 device
- PHP微信抢红包的算法
- RM delete file
- Go language foundation ----- 05 ----- structure
- Usage of (case, when) in PostgreSQL
- Structure of golang
- [at] ABC 258g - triple Reach - violence
- 【踩坑系列】mysql 修改root密码失败
- Getting started with minicom
- 【LeetCode】2. Valid Parentheses·有效的括号
猜你喜欢
Redis批量启停脚本
Go language foundation ----- 07 ----- method
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
【cocos creator】点击按钮切换界面
Project experience sharing: realize an IR Fusion optimization pass of Shengsi mindspire layer
什么是数据类型?数据类型有什么用?
The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.
Go language foundation ----- 15 ----- reflection
Iterm2 setting
密西根大学张阳教授受聘中国上海交通大学客座教授(图)
随机推荐
Go language foundation ----- 16 ----- goroutine, GPM model
PAT甲级 1031 Hello World for U
How does yarn link help developers debug NPM packages?
技术干货|昇思MindSpore NLP模型迁移之Bert模型—文本匹配任务(二):训练和评估
JS to implement publish and subscribe
OSPF experiment
Go language foundation ----- 09 ----- exception handling (error, panic, recover)
华为交换机基础配置(telnet/ssh登录)
[at] ABC 258g - Triangle triples reachable - violence
Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition
JS common basic case sorting (continuous update)
[at] ABC 258g - triple Reach - violence
技术干货|昇思MindSpore NLP模型迁移之Roberta ——情感分析任务
Microsoft Security Response Center
Redis profile
2020-12-12
tp3.2和tp5.0的区别
技术干货|AI框架动静态图统一的思考
【LeetCode】2. Valid Parentheses·有效的括号
Technical dry goods | some thoughts on the future of AI architecture