Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

flatten in js without lodash

const array1 = [ 1, 2, 3, [4, 5, 6, [7, 8, 9, [10]]]];
//flattened using es6 js
const flattenArray2 = array1.flat();
// result: [1, 2, 3, 4, 5, 6, [7, 8, 9, [10]]]
const flattenDeepArray2 = array1.flat(Infinity);
// result: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

//flattened using lodash
const _ = require('lodash');
const flattenArray1 = _.flatten(array1);
const flattenDeepArray1 = _.flattenDeep(array1);
 
PREVIOUS NEXT
Tagged: #flatten #js #lodash
ADD COMMENT
Topic
Name
5+7 =