showing results for - "javascript array flat"
Emilia
09 May 2019
1let arr = [
2    [1, 2],
3    [3, 4],
4    [5, 6][7, 8, 9],
5    [10, 11, 12, 13, 14, 15]
6];
7let flatArray = arr.reduce((acc, curVal) => {
8    return acc.concat(curVal)
9}, []);
10
11//Output:  [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
Mathieu
05 Apr 2020
1// flat(depth), 
2// depth is optional: how deep a nested array structure 
3//		should be flattened.
4//		default value of depth is 1 
5
6const arr1 = [1, 2, [3, 4]];
7arr1.flat(); 
8// [1, 2, 3, 4]
9
10const arr2 = [1, 2, [3, 4, [5, 6]]];
11arr2.flat();
12// [1, 2, 3, 4, [5, 6]]
13
14const arr3 = [1, 2, [3, 4, [5, 6]]];
15arr3.flat(2);
16// [1, 2, 3, 4, 5, 6]
17
18const arr4 = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]];
19arr4.flat(Infinity);
20// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Alix
05 Jul 2016
1const arr1 = [1, 2, [3, 4]];
2arr1.flat(); 
3// [1, 2, 3, 4]
queries leading to this page
flatten function javascriptflatter array of arrays javascriptflatten an arrayhow to flatten an array in javascriptflat infinity in javascriptarray flat javascriptflatten array in array javascriptjs make array flatjavascript array flateflatten a array of arrys jsarray flat in javascriptflatten array of array jsjs flat aaray of arraysflatern js arrayflat array javascriptes6 flatten arrayjs flatarraynested array to single array typescriptnode js array flattenflatten nested array javascriptjs flat arrayflatten arraysjs array flattenarray flattenflatten the array javascriptjs array flatjavascript array flattenarray flatflat js arrayes6 nested arrayarray flatten javascriptjavascript convert array of arrays to arrayhow to flatten array of arrays javascriptjs flatjs flatten nested arrayjs flatten arrayflat array flatten javascriptflat an array jsflat array jsjs flatflatten arr jshow can i flatten array in javascript 3fjavascript make one array of arraysflat 28 29 javascriptconvert nested array to single array javascriptflatten array of arraysflatten a array javascripthow to flatten array javascriptarray flat mdnflat function javascriptflatten raay in jswhy flatten an arrayhow do you flatten an arrrayhow to flatten arrayflatten array of arrays javascriptjs flatten list of listsarray flat jsflatten array jsnested array to plain array javascriptflatten an array javascripthow to flat an array in javascripthow to convert a nested array to a single array in javascriptarray flat jsjavascript flatten array of arraysflatten the array in jsflatten array in jsflatten array javascriptjs arrray flattennode js flatten array flat 28 29 jsflat in jsjavascript flattenflatten example jshow to flat an array in javascript without using flat functionflatten in jsjavascript array flatflat 28 29 in javascriptjs flattenflatten infinite javasriptsflat out an arrayarray of arrays javascript flattenflat infinity javascriptnode flatten arrayjs flat array of arraysflatten the array in javascriptarray flatflatten arrayarray of array to arrayflatten array in javascriptjavascript flatjavascript flat arrayjavascript flat array of arraysjavascript flatten arrayjs array flatflat an array in jsarray flattenhow can i flatten a array in javascript 3fjavascript array flat