当前位置:网站首页>链式长取值
链式长取值
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
},
边栏推荐
- WorldView卫星遥感影像数据/米级分辨率遥感影像
- Technical dry goods | some thoughts on the future of AI architecture
- Worldview satellite remote sensing image data / meter resolution remote sensing image
- Pat class a 1030 travel plan
- PIP uses image website to solve the problem of slow network speed
- Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition
- [at] abc 258G - Triangle 三元组可达-暴力
- Introduction of novel RNA based cancer therapies
- Enter three times and guess a number
- 一个实习生的CnosDB之旅
猜你喜欢
What is a data type? What is the use of data types?
Go language foundation ----- 13 ----- file
PAT甲级 1032 Sharing
Redis批量启停脚本
How to configure GDAL under idea
技术干货|AI框架动静态图统一的思考
[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18
一篇文章让你读懂-曼彻斯特编码
Research shows that breast cancer cells are more likely to enter the blood when patients sleep
Docker installs MySQL and successfully uses Navicat connection
随机推荐
Go language foundation ----- 18 ----- collaboration security, mutex lock, read-write lock, anonymous lock, sync Once
Differences between tp3.2 and tp5.0
[MySQL 13] if you change your password for the first time after installing mysql, you can skip MySQL password verification to log in
Analysis of the problems of the 12th Blue Bridge Cup single chip microcomputer provincial competition
Pat class a 1031 Hello world for u
Redis view client connection
Usage of requests module
What to do after the browser enters the URL
技术干货|关于AI Architecture未来的一些思考
Uniapp learning records
Go language foundation ------ 12 ------ JSON
Go language foundation ------ 14 ------ gotest
一篇文章让你读懂-曼彻斯特编码
How to clear the console password for s7700 device
2020-12-12
【LeetCode】4. Best Time to Buy and Sell Stock·股票买卖最佳时机
华为交换机Console密码重置、设备初始化、默认密码
Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)
【LeetCode】2. Valid Parentheses·有效的括号
Go language foundation ----- 15 ----- reflection