loading
open in
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
const input = [ 1, 2, {'a':2.5}, 3, [4, [5, [6, 7], 8, [9, 0]]] ];

const flatten = (arr) => {
  for(var i = 0; i < arr.length; i++){
    if(Array.isArray(arr[i])){
      arr.splice(i, 1, ...arr[i])
      i--; 
    }
  }
  return arr;
};

flatten(input);
node v10.15.2 linux/amd64