当前位置:网站首页>链式长取值
链式长取值
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
},边栏推荐
- jsutlis
- Getting started with minicom
- Technical dry goods | alphafold/ rosettafold open source reproduction (2) - alphafold process analysis and training Construction
- PHP微信抢红包的算法
- Go language foundation ----- 05 ----- structure
- PAT甲级 1032 Sharing
- Pat class a 1030 travel plan
- Worldview satellite remote sensing image data / meter resolution remote sensing image
- Huawei s5700 switch initialization and configuration SSH and telnet remote login methods
- Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
猜你喜欢

【LeetCode】4. Best time to buy and sell stock

Screenshot tool snipaste

一篇文章让你读懂-曼彻斯特编码

Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does

PAT甲级 1029 Median

【MySQL 11】怎么解决MySQL 8.0.18 大小写敏感问题

Go language foundation ------ 12 ------ JSON

Pat class a 1031 Hello world for u

Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework

Go language foundation ----- 02 ----- basic data types and operators
随机推荐
Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
Go language foundation ----- 09 ----- exception handling (error, panic, recover)
PostGIS space function
Analysis of the problems of the 12th Blue Bridge Cup single chip microcomputer provincial competition
How to configure GDAL under idea
Redis view client connection
PHP常用排序算法
Worldview satellite remote sensing image data / meter resolution remote sensing image
华为S5700交换机初始化和配置telnet,ssh用户方法
static关键字
在浏览器输入url后执行什么
Differences between tp3.2 and tp5.0
Client server model
HDMI2.1与HDMI2.0的区别以及转换PD信号。
Robots protocol
技术干货|昇思MindSpore NLP模型迁移之Roberta ——情感分析任务
Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)
idea取消引用显示效果
Go language foundation ----- 18 ----- collaboration security, mutex lock, read-write lock, anonymous lock, sync Once
[at] ABC 258g - triple Reach - violence