当前位置:网站首页>链式长取值
链式长取值
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
},边栏推荐
- C2-关于VCF文件合并的几种方法
- Iterm2 setting
- LwIP learning socket (API)
- Go language foundation ----- 01 ----- go language features
- Go language foundation ----- 09 ----- exception handling (error, panic, recover)
- PHP微信抢红包的算法
- Redis profile
- Docker installs MySQL and successfully uses Navicat connection
- Shengsi mindspire is upgraded again, the ultimate innovation of deep scientific computing
- Pat grade a 1029 median
猜你喜欢

Go language foundation ----- 13 ----- file

Docker installs MySQL and successfully uses Navicat connection
![[untitled]](/img/3d/27a7229e3f0ccf0ca5ae1f00a92513.jpg)
[untitled]
![[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18](/img/9b/db5fe1a37e0de5ba363f9e108310a5.png)
[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18

What is a data type? What is the use of data types?

Harmonyos third training notes

Iterm2设置

PAT甲级 1029 Median

Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico

【LeetCode】2. Valid parentheses · valid parentheses
随机推荐
Go language foundation ----- 02 ----- basic data types and operators
STM32F103 SPI (pit Diary)
[step on the pit series] MySQL failed to modify the root password
【LeetCode】3. Merge Two Sorted Lists·合并两个有序链表
tp3.2和tp5.0的区别
Enter three times and guess a number
PAT甲级 1032 Sharing
【LeetCode】2. Valid parentheses · valid parentheses
Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation
技术干货|AI框架动静态图统一的思考
【cocos creator】点击按钮切换界面
技术干货|昇思MindSpore NLP模型迁移之Bert模型—文本匹配任务(二):训练和评估
EtherCAT state machine transition (ESM)
PAT甲级 1029 Median
【LeetCode】4. Best time to buy and sell stock
Go language foundation ----- 07 ----- method
How to configure GDAL under idea
Go language foundation ------17 ----- channel creation, read-write, security shutdown, multiplexing select
Client server model
华为交换机配置ssh登录远程管理交换机