当前位置:网站首页>(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)
}
边栏推荐
- (JS)数组排平(flat)
- VI exit exit VIM applicable novice
- 任职 22 年,PowerShell 之父将从微软离职:曾因开发 PowerShell 被微软降级过
- [digital signal modulation] realize signal modulation and demodulation based on am+fm+dsb+ssb, including Matlab source code
- (JS)数组中纯函数
- STM32F1與STM32CubeIDE編程實例-超聲波測距傳感器驅動
- matlab基础 max 求一维或二维数组的最大值+sleep(pause)
- map合并相同的键,值合并为列表
- Memory allocation - static storage stack heap and static variable
- Shell 中你不得不熟知的变量运用
猜你喜欢

西门子S7-200SMART控制步进电机的具体方法及示例程序

Bs-gx-017 online examination management system based on SSM

Online text filter less than specified length tool

Modbustcp protocol WiFi wireless learning single channel infrared module (round shell version)

Here comes the tutorial of datawhale recommendation system!

云原生开发必备:首个通用无代码开发平台 iVX 编辑器

Reids设计与实现

“AI x 科学计算”进行时,华为昇思 MindSpore 赛题火热开启,等你来!

Using EasyX configuration in clion

Modbustcp protocol network learning single channel infrared module (medium shell version)
随机推荐
[untitled] I am plotting a big event
[various * * question series] what are OLTP and OLAP?
【无标题】我在密谋一件大事
Shell 中你不得不熟知的变量运用
The necessary operation for those big guys to fly 666 inadvertently at the bash command line terminal
Modbustcp protocol network learning single channel infrared module (double-layer board)
Nuc980 open source project 16- start from SPI flash (w25q128)
np.astype()
(JS)状态模式
嵌入式驱动开发之uboot---uboot 中的常见命令参数参数
9 款好用到爆的 JSON 处理工具,极大提高效率!
Spark - Task 与 Partition 一一对应与参数详解
Stm32f1 and stm32subeide programming example - ultrasonic distance sensor drive
内存分配——静态存储区 栈 堆 与static变量
企业竞争分析的几种方法:SWOT、波特五力、PEST「建议收藏」
ModbusTCP协议WIFI无线学习型单路红外模块(小壳版)
【各种**问题系列】OLTP和OLAP是啥?
Here comes the tutorial of datawhale recommendation system!
(JS)捕获错误(异常)
PyTorch学习笔记(6)——DataLoader源代码剖析