Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

flattenDeep in es 6 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: #flattenDeep #es #lodash
ADD COMMENT
Topic
Name
6+8 =