How to flatten all layers of nested array in TypeScript

1 Answer

0 votes
let arr = [ 1, 5, [[2]], [[[7]]], [[[[[[[99]]]]]]] ];
 
arr = arr.flat(Infinity);
 
console.log(arr);
  
   
   
    
/*
run:
    
[1, 5, 2, 7, 99] 
    
*/

 



answered May 22, 2022 by avibootz
...