当前位置:网站首页>JS 数组扁平化 (递归写法)
JS 数组扁平化 (递归写法)
2022-06-22 07:26:00 【铁骨铮铮学编程】
let manyArr = [[5, 7, 4], 3, [89, [8, 9]]]; // 需要处理的目标数组
function flat(arr) {
let newArr = []
for (let _i = 0; _i < arr.length; _i++) {
// 这里判断当前下标的值 是否还是数组类型
if (Object.prototype.toString.call(arr[_i]).slice(8, -1) == 'Array') {
newArr = [...newArr, ...flat(arr[_i])]
} else {
newArr.push(arr[_i]);
}
}
return newArr
}
manyArr = flat(manyArr);边栏推荐
- IDEA连接不到SQLSSMS
- Typescript & explain in, keyof, extensions, index signature, record and typeof in detail (updated from time to time)
- Notes on algebra 10.1: understanding of symmetric polynomials and derivation of cubic resolvents
- Get through - coupons
- 从暴力递归到动态规划
- Open version - write off
- Flutter black triangle
- Kinect azure based multi camera data collection (I)
- Open version - order delivery
- 网站预缓存代码
猜你喜欢

Color matching of architecture diagram

Chromedriver所有版本下載

Coursera self driving car Part4 motion planning finalproject principle and key code analysis

Antd framework: click the link to reopen the browser page - Basic accumulation

antd——a-upload-dragger拖拽上传组件——基础积累

RFID仓储管理系统解决方案实施可视化流程

Canoe uses tricks to export data from logging file/trace to Matlab for analysis

Real MySQL interview question (18) -- practical operation analysis

What are the ways for Taobao merchants to put their babies on the shelves in batches

Image interpolation (nearest neighbor, bilinear)
随机推荐
Matlab uses deep learning recurrent neural network RNN long-term and short-term memory LSTM to predict waveform time series data
校招路上的坑
antd——a-upload-dragger拖拽上传组件——基础积累
The solution of word document being locked and unable to edit
Detailed explanation of capturing the whole store treasure and uploading it to multiple stores
Chromedriver所有版本下载
How was the coffee supply chain leveled?
RFID warehouse management system solution implementation visualization process
How to authorize a picture in a store to another store? What are the methods of unauthorized replication
Flutter black triangle
Coursera self driving car Part4 motion planning finalproject principle and key code analysis
Multi camera data collection based on Kinect azure (III)
Multi camera data collection based on Kinect azure (II)
Assembly learning Chapter 4 of assembly language (Third Edition) written by Wang Shuang
How to backup the treasures in the store and upload them to multiple stores
Wechat applet camouflage page (change the page content regularly)
Application and problem solving of robotframework
CONDA installation method of deepmd kit and the solution of slow speed
Flutter uses the for loop
Use of the thrust Library in CUDA