showing results for - "js flatten"
Roberta
29 Feb 2018
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 ]
Timothe
23 Feb 2016
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]
Julián
24 Nov 2017
1var arrays = [
2  ["$6"],
3  ["$12"],
4  ["$25"],
5  ["$25"],
6  ["$18"],
7  ["$22"],
8  ["$10"]
9];
10var merged = [].concat.apply([], arrays);
11
12console.log(merged);
Stella
15 Jul 2020
1const arr = [1, 2, [3, 4]];
2
3// To flat single level array
4arr.flat();
5// is equivalent to
6arr.reduce((acc, val) => acc.concat(val), []);
7// [1, 2, 3, 4]
8
9// or with decomposition syntax
10const flattened = arr => [].concat(...arr);
11
Valentín
30 May 2020
1import { flatten } from "ramda";
2
3const flattenArray = flatten([1, [2, 3]])
Matías
03 Jun 2016
1const flatten = (ary) => ary.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [])
2
queries leading to this page
flat an arrayflattening an array by concatflatten for each javascriptflatten array of array itemsjs flat array of two arraysflatten es6javascript flatten array and mergejavascript flat the array until it 27s flatjs flatten nested arraymdn flatten arrayunwrap array javascriptflatten nnested arraynode flattenflatten an object to form an array jsconcat array of arrays javascriptflatteren in jsjs flatten 28 29js flat functionflatten array js with constant spaceflatten array in jsflatten list jsflattend array of arraysflatten array function jsflatten the array javascriptjavascript best way to latten arrayflat array nodejsmake nested array flatten jsflatten the javascript arrayhow js flatten worksarr flathow to make a flat array in javascriptarray of arrays to single array javascriptmerge nested arrays javascriptflaten arrays javascriptjavascript flatten arrayjs flat arraysjavascript flatern arrayhow to flatten an arryaflattening a nested arrayflatten 2d array javascriptflatten everything javscriptjavascript flatten one layerjs flat infinityturn an array of arrays into a single arrayflat function in javascriptflatten an array flattening array using concat in javascriptflat js infinitejs flatten array of arraysjs flat 28 29flatten nested array in objectjs flatten arrarray flat javadcriptjavascript array flat 28 29js array flatarray of arrays into one arrayjavascript array flatten 28 29flatten arres6 flatten object of arraysflat javascript mdnnodejs array flatjavascript convert array of arrays to arrayflatten angular 8flattening array of arrays javascript using isarray 28 29array of array to one arrayjs array of array flattenflattenarray in javascriptjavascript flattenarrnested array to one array javascriptflatten nested array in javascriptflattening of arrayjavascript combine array of arraysjs flatt arrayjs array index not flatflatten two dimensional array javascriptarray and ovject flatten codehow to convert array of arrays into single arrayturn array of arrays into one arrayarray flatmulti level array flatten javascript2 array prototype flat 28 29flat functions in javascriptjs concat array of arraysflatten aaray in javascriptnested array to single array javascriptarray flatten node jsjs array flat protoflat arrayarray flatten in javascripthow to flatten nested arraysflat array in javascriptreact native flatten arrayflatten js functionflattening arraysarray flat dev firefoxflatten an array in javascriptjavascript flat multidimensional arrayjs arrays flatnested array to plain array javascripthow to return a flatten arrayhow to flat array or arrays angulararray flat 28 29 jsflatten in javascriptarray flatten 28 29javascript array flatten onlinearray faltjs array flat alljs merge array of arrays into onejs flat array of arrayjavascript flatten list of listjavascript array flat methodflat inifint jsflatten an array to a single array javascriptflatten array of arrayscombine nested arrays javascriptjs flatten an array of arrays flat in jshow to flatten an array of arrays in javascriptreduce multiple array with array prototypejs flat array of arrayswhat does it mean by flatten arrayarray flatteningjavascript array flatmake all arrays in an array into a single array javascriptextract outer array in javascriptwhich method do you prefer to flatten an array 26 why 3f one 3a arr flat 28 29 3b two 3a 5b 5d concat 28 arr 29 3b three 3a arr reduce 28 28acc 2c val 29 3d 3e acc concat 28val 29 2c 5b 5d 29 3barray to array of arrays javascripthow di i flatten a 2d array jsobject values 28 29 flat 28 29what does flattening the array meanflat in arrayarray flat node jsarray flat combinesflatten a array javascript flatten jsflat the array in jsflaten an array javascriptflatten array 2cjavascript join all nested arrayun flat array javascriptflat arrays es6array flat infinity flat 28 29javascriptjoin array of arrays javascriptflatten tree to array javascriptflat method in javascriptvalue flat jses6 flatnode flatted arrayjavascript make flat arrayarray flat 28 29 javascriptconcat array flattenflat 28 29flat list js flat 28 29flattendeep javascriptconvert a nested array into a flat array flatten array javascript spreadflatten the array in javascriptarray of arrays to one arrayflat arrqayjs unwrap array if single elementnode js flatten array 27flattening array of arrays jsflatten an array of arraysflat mdnarr flattenjavascript flatten array of objectjava script flathow to retrun a flattend arraywhat does flatten method in javascript doarray squashhow to fltten an arrayhow to make a flatten function from scratchhow to flatten arraydocsjavascript flatten arrayhow to flat array into one objectjs flatten an arrayarray of partical array flatten js flat javascripttypescript flatten array of arraysflatten array javascriptflatten array aof arry in js 5b1 2c2 2c 5b3 2c4 5d 2c 5b 5b5 2c6 2c7 5d 5d 5d js to flatjavascript nested map flattenarrays flattenflatten 28array 29 jsjavascript array or arrays unnestdeep flatten array jshow to flat array jsnodejs group array 10 array flatflat 28 29 arrayflattening an array of array in javascriptflatten array of array jses6 flatten array of arraysarray flatten tsjavascript flatten nested arrays es6how to flatten js arrayvue js array flatmdn javascript array flatternflatten a nested array javascriptflattern array jsflat array method javascripthow to flatten array in nodejshow to flatten collection with arraysjavascript array flattenexpand nested array javascriptspread all arrays inside an arrayjs flatten araryreact flat 28 29flatten 28array javascript 29how to flatten an array of arrays javascript es6flatten array of arrays jces6 nested arrayuse of flat in javascriptflatten an array jsgiven an array of arrays 2c flatten them into a single array array flattenjavascripthow to flatteb list in javascriptjs flatarray flat mdnflat mdn jsflat an array javsacriptflat out an arrayarray js flattenjavascript array flatflatten arrays in arraysflatening an array in jsflatten the arrayarray of arrays to arrayflat javascriptflat array to array of arrayflatten an array of array of numbershow to flatten deep arrayjs es6 flatten arrayjavascript array of array flattenjavascrtip flatten arrayflat array infinite jsjavascrpt flattenhow to fltten an array 2d jsflatten array of arrays javascriptflatten 2 arrays in javascripthow to flat array in javascriptjavascript flatten array of arraysflat array inside arrayflattening nested array javascripty jsflatten arraflatten array object javascriptjavascript array reduce concat stringarray flat javascripthow to flat the array javascriptflatten a javascript arrayarray flat javascriptjavascript arra flatflatten array nodejsjavascript flatten an arrayarray flatten js when to useflatten function javascript flat jsflat jsflattening out an arrayarry flatflatten array of array javascriptflattening arrayflat 28 29 javascriptflattening of array javascriptflat a arrayflatenned arrayjs spread array into array instead of nesting arraysjavascript flat arrayflatten array methodflatern js arrayalternative to flat 28 29javascript flat methodhow to flatten a nested array javascriptnode js flatten arrayalgorithm behind flat in jsadd array of arrays into one array javascriptflat all array of arrayremove array from array javascript flatjavascriopt flattenjavascript flatten array of arrays in single arrayjs make array flatjavascript flatten listconvert deeply nested array to flat array javascriptflatten in jsflatten array nodehow to use flatten jsmake array flat jsjavascript es6 flatten arrayflatten jsarray of array to arrayarray flat in javascriptflatten 2d array jsflatten array of arrayflattened arrray javascriptarray of arrays join jsflattena rray jshow to flatten arrays inside arrays jsflat array google scriptjavascript best way to flatten arrayjavascritp flatten an arrayuconver array of arrays to single array javascriptflat array of arrayhow to flatten array of arrays javascriptarray flatten objectsarray in array to one array jsflatten infinite javasriptsarray flattencombine array of arrays jsarr reduce to concat arrayswhy flatten an arrayflat nodejsjs array flat 28 29arr flat 28es6 flatten 28array 29flat infinity in javascriptflat array javascriptarrar flattenflatten list of lists javascriptflatter array jsjavascript combine nested arrayshow to flatten the arrayflatten array in javascript es5changes object to array flattent data javascriptflat method in jsjs arrray flatflatten arary jses7 flatten arrayjavascript array of arrays to single arrayhow do you flatten an arrrayjavascript flatten array es6array in array flatflattening the arrayflatten multidimensional array javascriptarray flatenarray faltjs join nested arrayflatten array a single level javascriptflatten array of ararys jsflattening array javascriptarray flat alternative lodashjs array flat methodarray flat array flat mdnflatten array functionflattening jsnumpy flatten arrayflat method javascripthow do i flatten an arraynodejs flatten arrayjavascript make one array of arraysjavascript concat nested arrayflat arrays in js using reducejavascript array unwrapflatten an list of arrays in javascriptflat js arrayjs 2c flaten an arrayhow to flatten array in javascriptflat function javascript operator js array flatarray flat method example in javascriptjs flatten nested arraysjs flatten arryhow to create array flatten function javascriptjs flat pusharray flattetningflatten a nested array in typescriptjs flatten list of listsarray flat jsflat array with hiralquyflatten array of 150 arrays javascriptflattening a array of arraysjs flatten array 21ghow to flattern array of arraysflatten array concatflat an array in js flat 28infinity 29 in javascriptarray flat 28 29 method in javascriptflat infinity javascriptflatten an array of objectsjavascript reduce 2d array to 1d arrayflattent a arrayconcat and flat multi diminsional arrayarray flattening concept in javascriptarray flatten jsjs array flat flatten whyhow to flatten a 2d array in jsjoin array of arrays es6array fllatjs flaten listmdn array flatjs flattenhow to make array in array flat javascriptarray flating in jsjs invrse array flathow to flatten a aeray in javascriptarray of arrays flat javascriptjavascript array flatten objectsjs flat aaray of arrayshow to flatten a arrayarray of array to one single arrayjs array flattenflattening array in javascriptflatten array of onarray flat js concatarray 23flat 28 29 flatten javascriptarray flatten es6flatten array react jsarray flatten javascriptarray flat vs concat javascriptarray flat jsjavascript faltten arrayflatten arrays jsone options array flat garna mil6javascript flatten array of objectsflatten 28 29 javascriptnode flatten array7conver array of arrays to single arrayflatten example jsjs array reverse concatjs flatten array one levelflatten array es6javascript how to flatten a nested arraywhat 27s flatten in javascriptflatten arryjs flat 28 29flatter array of arrays javascriptflatten an array javascript without flatflatten a lsit of lists javascriptflat array of arrays javascripthow to flatten an array of arrays javascripthow to flatten an array of arrayjs flatten array of arrays into arrayjs array flat nodejs flat arrayflatten javascript arrayjavascrip flatten arrayflatten array in array javascriptflatten array in javascriptjs convert 2d array to 1djs array of arrays flattents using flat on objects with arraysflatten nested array javascriptjavascript flatten all arrayshow to turn a 2d array into a 1d array js flat methodhow to flatten the array in javascriptnode flatten arrayarrays flattencan i use flathow to flatten nested arrays javascriptflaten arraysflat push arrays jsmake a flat array from array of array listarray6 flat jsarray flatten mdnnode array flatreduce arrays inside array javascripthow to convert a nested array to a single array in javascript flatten 28 29 typescriptflatten the array in jsflatten get values in nodearray flatways to flatten an array jsmap reduce flatten javascriptjs how to flatten an arrayarray flat developer firefoxhow can i flatten a array in javascript 3fflat elements in array javascriptflat an array jsjs flatten allnodejs array flatreturn the flattened version of the arrayjs array flatjs flatten 2d arrayflatten jsflattening javascript arrayflatten method in javascriptjavascript array flat functionmake nested array one arrayflattening a list in javascriptflatten an array in jsflat array in jshow to flatten a 2 d array in js with flatarray flatflat 28 29 3bjavascript flattenarr flat 28 29js flatten array with flatjs array flattenhow to reduce 2d array to one array javascriptjavascript flatten outter array by one leveljavascript flatten array w3schoolsnode js array flatoposite of array flatflat in jsflat array of objects javascriptfalttening an array programmingcombine array of arrays javascriptwhat does flattening an array mean 3fjavascript flaten array and access the keyarray of partical array flattenjs collaspse arrayarray flat in javascriptjavascript flatten array one levelarray flattenjavascript array of arrays flattenflatten array of array in jsflatten two arraysjavascript flattenflat array jsflatten array of satrings javascriptflattens in jsjavascript flatten array with one valuejavascript flatten embedded arrays to array of objects flat node jsreduce to flatten array filterflatten arrays javascriptextra flat jswhat is array flatjavascript flat array function flat method angularflatten arr jsflattening an array flat 28 29 in javascriptjavascript how to flatten arrayjavascript flaten array of arrayjavascript how to flatten a clamped arrajs flatten filter resultflatten the arrays jsflat array angularflaten arrayflat array methon in javascripthow to flatten and array in jsjs flatarrayhow to change array of arrays into single arrayarray 5b 22flat 22 5dflatten array of arrays in javascriptjs arrray flattenturn array of arrays into one array javascriptarray of arrays flatten javascriptes6 array flat 5cflatten an array of arrays javascriptjs toflatjs array how to flathow to flatten an array javascriptflattenarray jshow to flatten an arraytypescript array flatts flatten numberget flat array from array of arrays flat 28 29 lengthflatten array js without flathow to flatten a 2d array javascriptfunction flatten jsjavascript flatten 28array of objects 29javascript array flat allflattening array js implementationhow do i flatten an array thats in an array in jsflatten arrahow to flatten array javascriptnode js array flattenflatten js arrayjs flatten the arrayjs flatten arrayflat the array of array into array in jsjs flat arrau flat 28 29 javascriptpush flat in reduce javascriptflatten javascript arrrayjs array flattenarray of object to flat array js es6array of arrays javascript flattenhow can i flat an array in javascript 3fflatten array of arrays with keys javascriptjavascript flatten array functionopen nested array one list javascriptflattening nested arrays javascriptarray prototype flathotw to flat array of arrayjs flatflatten array fjs flatten functioinhow to use reduce to merge array of arraysargs flat 28 29 javascriptconcat array of arrays jsflatten array flat 28 29 2b javascriptjs make flatten functionjs flatten aflatten list javascriptflat i jsflatten arrayssjs flattenrts flatten object to arrayflat the arrayfaltten an array javascriptflatten array attributes javascriptlist flat javascripthow to flat array javascriptarray of array to array javascriptflatten array of objects javascriptjavascript flatten funtionarray flat javascript mdnjavascript join array of arraysnested array and make into one javascriptjs concatenate array of arraysjs flatten arayhow flat an array jsconvert array of arrays to array javascriptreduce array of arrays into separate variables javascriptjavascript 2b nested array into single arrayjavascript array to array of arrayshow to flatten a 2 d array in jsflatten arraysimplement flatten function jsjavascript flathow to make nested array in to one arrayarr flatjavacsript flatten arrayflatten array node jsflat infinity jsarray flatten function javascriptfaltten an arrayhow to flat an array in javascriptflatten nested arraysflatten javascriptjavascript flatten 2d arraynested array make it single array javascriptflatten an arrayhow to write flatten function from scratch javascriptangular flat joinjavascript array flatehow to flatten an array in javascript wothout flatenarray metodo flates6 flatten arrayjavascript flatten nested arrayjavascript string array to flat arrayjavascript list flattenflat and reduce in javascriptjavascript flattern arrayflat javascript arrayflat an array javascriptarray flatten jshow to flatten an array in jsjavascript join nested arrayflatten array javascript codehow to flatten an arr jsjoin nested arrays javascriptwhy is array flat not working in nodeflat all array in array jsnested arrays into a single arrayarray of array to single array javascriptjavascript arr flattenjs concat nested arraysjs collapse arrayarray flat javascript definitionget all flat array javascripthow to flat an array in javascript without using flat functionflatten node listjavascript arr fattenextrans nested array and flat in javascriptjs flattern arrayjavascript flat functionflatten an array within an arrayconvert array of arrays into single arrayjoin array of arraysarray of arrays flattenmdn flatnode js flat array flatflatten array jsflatten array or arrays javascriptbesto option to flatten an arraycollapse array javascriptjavascript flatflatten array in es6 without inbuilt functionsreduce multiple arrays into onehow to flatten an array of arraysarray flat valuearray flatten javascriptflatten arayflatten array javascriptmerge nested arrays jsjavascript how to flatten an array flatten javascript mdnjs array flatten why flat arrayconvert nested array to single array javascriptdeep flat array javascriptflatten an array javascripthow to flatten array javascript without flat 28 29javascript flat array of arraysusing map to concat array of arraysjs flattebhow to flatten an array in javascriptmdn array flattenflat 28infinity 29flatten array 28 29nested array to single array typescriptjavascipt array flattenmdn flatten an arrayhow to flaten a 2d array javascriptwhat is flatten an arrayflattening an array javascriptflattenn the arrayarray methods javascript flatflaten a nestes array of objectsjavascript flatten an array of arrayscreate a single array from a nested arrayhow to flatten multi level arrays javascriptflatten matrix javascriptjs unfold arraynested arrays javascript in onejavscript array of object flatflatten array of arrays jsflatten array javacdriptarray flatarray flat in jsjavascript array flatjavascript concat array of arraysflat in javascriptflatten a nested arrayarray flatternnode flat array of arraysflatten array of arrays es6flaten array javascripthow can i flatten array in javascript 3fflatte arrayflatten array javascript es6convert array to flatflatten raay in jsflattening array jsflaten array jsmdn flatarray flat nodejsflat on arrayhow to flatten an array jsjs array of arrays to single arrayhow to flatten an array of strings in jsflaten an arrayarray flat methodflatten a array of arrys jsnode flat arrayflat the n dimenional array javascritflattening and arrayflattening an array in javascriptarray flatten 28 29 jsflatten array javascript without methodarray prototype myflattenflatten array with flatjavascript flattan array of arraysjs flatten array in arrayflettern arrayjavascript array flat alternativealternative of flat in javascriptjavascript flatten array with one value convertflat 28 29 in javascriptarray javascript flattenjavascript array flattenarray of array flatten jshow to flatten collection with arrayhow deep does array flat goflatten a arrayflatten array javascript function flat array as objects mdnjs flatten