当前位置:网站首页>JS method of changing two-dimensional array to one-dimensional array
JS method of changing two-dimensional array to one-dimensional array
2022-06-30 12:53:00 【Sister Chunfeng】
Method 1 :
utilize es5 Of reduce Realization .
var arr1 = [[0, 1], [2, 3], [4, 5]];
var arr2 = arr1.reduce(function (a, b) {
return a.concat(b)
});
Method 2 :
adopt Array.isArray Determine whether it is a multidimensional array , If it is , Do recursive operations .
var arr1 = [[1,2],3,[[[4], 5]]];
function flatten(arr) {
return [].concat( ...arr.map(x =>
Array.isArray(x) ? flatten(x) : x
))
}
var arr2 = flatten(arr1);
Method 3 :
utilize apply Realization .
var arr1 = [[0, 1], [2, 3], [4, 5]];
var arr2 = [].concat.apply([], arr1); // perhaps Array.prototype.concat.apply([], arr1);
边栏推荐
- 2022-06-23 帆软部分公式及sql生成(月份、季度取数)
- 产品经理专业知识50篇(七)-如何建立一套完整的用户成长体系?
- Js根据相同值将数组转换为二维数组
- Spatiotemporal prediction 2-gcn_ LSTM
- Illustration creating a stored procedure using Navicat for MySQL
- RDS MySQL数据迁移PolarDB MySQL费用可以转过去吗?
- Flink sql控制台,不识别group_concat函数吗?
- LeetCode_栈_中等_227.基本计算器 II(不含括号)
- Unity脚本的基础语法(1)-游戏对象的常用操作
- ERROR: Cannot uninstall ‘PyYAML‘. It is a distutils installed project and thus we cannot accurately
猜你喜欢
![[surprised] the download speed of Xunlei is not as fast as that of the virtual machine](/img/04/b0d23266b70c9ad6990a5203ef8ddf.png)
[surprised] the download speed of Xunlei is not as fast as that of the virtual machine
![[qnx hypervisor 2.2 user manual]6.2.3 communication between guest and external](/img/ca/9065325ce8882d95fb24c82fb62abc.png)
[qnx hypervisor 2.2 user manual]6.2.3 communication between guest and external

【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(二)

Visual Studio配置Qt并通过NSIS实现项目打包

Basic interview questions for Software Test Engineers (required for fresh students and test dishes) the most basic interview questions

黑马笔记---List系列集合与泛型

MATLAB小技巧(22)矩阵分析--逐步回归

Motor control Clarke( α/β) Derivation of equal amplitude transformation

【OpenGL】OpenGL Examples

【一天学awk】基础中的基础
随机推荐
Wechat applet reports an error: typeerror: cannot read property 'SetData' of undefined
postman 自动生成 curl 代码片段
写信宝小程序开源
[yitianxue awk] regular matching
Today in history: Microsoft acquires PowerPoint developers; SGI and MIPS merge
Q-learning notes
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年6月29日21:59:34
QT implementation dynamic navigation bar
Dataworks synchronizes maxcomputer to sqlserver. Chinese characters become garbled. How can I solve it
Apple executives openly "open the connection": Samsung copied the iPhone and only added a large screen
Dark horse notes -- wrapper class, regular expression, arrays class
【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(二)
Tencent cloud Database Engineer competency certification was launched, and people from all walks of life talked about talent training problems
kubeedge的核心理念
Database usage in QT
Unity的脚本的基础语法(2)-Unity中记录时间
排查问题的方法论(适用于任何多方合作中产生的问题排查)
Postman automatically generates curl code snippets
RDS MySQL数据迁移PolarDB MySQL费用可以转过去吗?
Analysis of smart jiangcai login in Jiangxi University of Finance and Economics