JAVASCRIPT
JavaScript flatten an array
let arr = [
[1, 2],
[3, 4],
[5, 6][7, 8, 9],
[10, 11, 12, 13, 14, 15]
];
let flatArray = arr.reduce((acc, curVal) => {
return acc.concat(curVal)
}, []);
//Output: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
flatten an array javascript
var arrays = [
["$6"],
["$12"],
["$25"],
["$25"],
["$18"],
["$22"],
["$10"]
];
var merged = [].concat.apply([], arrays);
console.log(merged);
javascript array flatten
const flatten = (ary) => ary.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [])
array flatten
const arr = [1, 2, [3, 4]];
// To flat single level array
arr.flat();
// is equivalent to
arr.reduce((acc, val) => acc.concat(val), []);
// [1, 2, 3, 4]
// or with decomposition syntax
const flattened = arr => [].concat(...arr);
JavaScript flatten an array
let arr = [
[1, 2],
[3, 4],
[5, 6][7, 8, 9],
[10, 11, 12, 13, 14, 15]
];
let flatArray = arr.reduce((acc, curVal) => {
return acc.concat(curVal)
}, []);
//Output: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
flatten an array javascript
var arrays = [
["$6"],
["$12"],
["$25"],
["$25"],
["$18"],
["$22"],
["$10"]
];
var merged = [].concat.apply([], arrays);
console.log(merged);
javascript array flatten
const flatten = (ary) => ary.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [])
array flatten
const arr = [1, 2, [3, 4]];
// To flat single level array
arr.flat();
// is equivalent to
arr.reduce((acc, val) => acc.concat(val), []);
// [1, 2, 3, 4]
// or with decomposition syntax
const flattened = arr => [].concat(...arr);