当前位置:网站首页>ES10 subtotal flat and flatmap
ES10 subtotal flat and flatmap
2022-07-24 06:35:00 【LuciferDawnC】
1.flat()
Flattening arrays , Or array dimensionality reduction !
adopt
let arr = [1,[2,3],5,[4,[6,7]]];
let arr2 = arr.flat(); // Reduce the dimension of the array to [1,2,3,5,4[6,7]]
Simply put, the array in the array is disassembled and inserted into the current position
flat() It can take parameters, and the default is 1 in other words
let arr2 = arr.flat(); The equivalent is let arr2 = arr.flat(1);
The function of the parameter is to identify the multidimensional array of reduced dimensions as 2 The third level subarray contained in the time array [6,7] It will also be resolved as [1, 2, 3, 5, 4, 6, 7]
2.flatMap()
This method and flat It will also reduce the dimension of the array However, this method will only reduce the dimension once And the elements in the array can be iterated through return return ( It doesn't change the original array You need to use a variable container to accept )
let arr = [1,[2,3],5,[4,[6,7]]];
let arr2 = arr.flatMap(item => {
// It can be calculated here
// return The number will generate a new array
return item
}); // Reduce the dimension of the array to [1,2,3,5,4[6,7]]
console.log(arr2, arr)
// [1, 2, 3, 5, 4, Array(2)] [1,[2,3],5,[4,[6,7]]]
边栏推荐
猜你喜欢

Combination of grep and regular

系统安全及应用

Playing RTSP video stream on webpage

Custom MVC 1.0

常用工作方法总结(7S、SWOT分析、PDCA循环、SMART原则、6W2H、时间管理、WBS、二八原则)

List of problems in the re disk guidance of the project

LVM and disk quota

Flink production environment configuration recommendations

Do not rent servers, build your own personal business website (1)

Common commands and package management of go language
随机推荐
go语言常用命令和包管理
Custom MVC 2.0
Do not rent servers, build your own personal business website (2)
Go environment construction and start
Leetcode sword finger offer jz73 flip word sequence
自定义zabbix agent rpm包
XML parsing
Server hardware and RAID configuration practice
Sed command
Do not rent servers, build your own personal business website (4)
LVM与磁盘配额
【301】怪诞行为学-可预测的非理性
IP notes (9)
Set up a WordPress personal blog locally and launch it through the intranet (22)
Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]
【219】app 测试和web测试的区别点?
【217】#!/usr/bin/env 的意义
Flink checkpoint configuration details
go的环境搭建和起步
系统安全及应用