Javascript flatten array of arrays
// flat(depth),
// depth is optional: how deep a nested array structure
// should be flattened.
// default value of depth is 1
const arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]
const arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]
const arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]
const arr4 = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]];
arr4.flat(Infinity);
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]var arrays = [
["$6"],
["$12"],
["$25"],
["$25"],
["$18"],
["$22"],
["$10"]
];
var merged = [].concat.apply([], arrays);
console.log(merged);var multiDimensionArray = [["a"],["b","c"],["d"]]; //array of arrays
var flatArray = Array.prototype.concat.apply([], multiDimensionArray); //flatten array of arrays
console.log(flatArray); // [ "a","b","c","d"];
Also in JavaScript:
- tsconfig.json not generated
- express get host url
- how to check version of node js in cmd
- kill node process
- jquery get value by name
- vscode user snippets
- javascript tracking webcam
- jquery reload page
- how to find out what a string ends with in javascript
- javascript redirect browser
- javascript get number of elements in object
- js find longest word in string function
- cordova js how to load local file in subdir
- create nodejs new object
- how to display current date and time in angular
- exploding string with comma using jquery
- javascript string return character
- node read file stream
- Create a node in the Node Editor or Hypershade, press the ____ and type into search bar:
- javascript alert program
- owl carousel json not working
- longitud objeto javascript
- jquery select option by value
- regex contains string in end