当前位置:网站首页>(JS) array flat
(JS) array flat
2022-06-29 11:12:00 【Yu Cainiao, who asked not to be named】
- If there is only one layer of nested arrays
Array.prototype.concat.apply([], arr)
or
[].concat(arr)
or
Array.prototype.concat.call([], arr[0],arr[1]...)
- If there are multiple nesting
function flat(arr) {
// Determine whether there is a multi-layer array
const isDeep = arr.some(item => {
return item instanceof Array;
});
// If there is no multi-level array , Then return to arr
if (!isDeep) {
return arr;
}
const res = Array.prototype.concat.apply([], arr);
return flat(res)
}
边栏推荐
- MATLAB basic Max to find the maximum value of one-dimensional or two-dimensional array +sleep (pause)
- misc3~7
- 5.移植uboot-设置默认环境变量,裁剪,并分区
- 添加通知公告,给在线用户发送通知
- Lizuofan, co-founder of nonconvex: Taking quantification as his lifelong career
- 由ASP.NET Core根据路径下载文件异常引发的探究
- Week 12 experiment -- implementation of VGA protocol based on FPGA
- Mastering the clever use of some shell wildcards will make us write with half the effort
- Modbus RTU 协议485学习型2路红外模块
- 非凸联合创始人李佐凡:将量化作为自己的终身事业
猜你喜欢

在Clion中使用EasyX配置

Exemples de programmation stm32f1 et stm32cubeide - entraînement du capteur de portée ultrasonique

BS-GX-017基于SSM实现的在线考试管理系统

Spark - Task 与 Partition 一一对应与参数详解

BS-GX-018 基于SSM实现在校学生考试系统

【FreeRTOS】08 互斥信号量、优先级反转问题

Modbustcp protocol network learning single channel infrared module (double-layer board)

Graduation season · advanced technology Er - workers in the workplace

多线程实现客户端与服务端通信(初级版本)

How to obtain method parameter values through WinDbg
随机推荐
涂鸦云开发 demo 登录
VI exit exit VIM applicable novice
(JS)手写深比较
(JS)手写深拷贝
期未课程设计:基于SSM的产品销售管理系统
Easydss is deployed on Disk C, and the video playback cannot be played normally. How to solve this problem?
Course design for the end of the semester: product sales management system based on SSM
nuc980 已成功启动
5.移植uboot-设置默认环境变量,裁剪,并分区
Bs-gx-017 online examination management system based on SSM
MySQL query table field information
Google Earth engine (GEE) - Gedi L2a vector canopy top height (version 2) global ecosystem data set
【FreeRTOS】08 互斥信号量、优先级反转问题
[digital signal modulation] realize signal modulation and demodulation based on am+fm+dsb+ssb, including Matlab source code
Does anyone encounter this problem when flinkcdc synchronizes MySQL?
What happened during the MySQL installation?
Modbus RTU protocol 485 learning 2-way infrared module
Modbus RTU 协议485学习型2路红外模块
Mysql查询表字段信息
“AI x 科学计算”进行时,华为昇思 MindSpore 赛题火热开启,等你来!