TIL flattening arrays
POSTED ON:
TAGS: javascript
Have an array inside your array inside your array?
let theArray = [1, 2, [3, 4, [5, 6]]];
// flat() method
theArray.flat(0); // DOES NOTHING: [1, 2, [3, 4, [5, 6]]]
theArray.flat(); // DEFAULT: [1, 2, 3, 4, [5, 6]]
theArray.flat(1); // [1, 2, 3, 4, [5, 6]]
theArray.flat(2); // [1, 2, 3, 4, 5, 6]
theArray.flat(3); // [1, 2, 3, 4, 5, 6]
Related TILs
Tagged: javascript