How to flatten part of nested array in TypeScript

1 Answer

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

 



answered May 22, 2022 by avibootz
...