How to empty an array in TypeScript

2 Answers

0 votes
let arr = [1, 2, 3, 4, 7, 9];
console.log(arr);
 
arr = [];
console.log(arr);
   
   
     
       
       
/*
run:
       
[1, 2, 3, 4, 7, 9] 
[] 
       
*/

 



answered Jan 17, 2022 by avibootz
0 votes
let arr = [1, 2, 3, 4, 7, 9];
console.log(arr);
 
arr.length = 0;
console.log(arr);
   
   
     
       
       
/*
run:
       
[ 1, 2, 3, 4, 8 ]
[]
       
*/

 



answered Jan 17, 2022 by avibootz

Related questions

2 answers 119 views
2 answers 130 views
1 answer 117 views
1 answer 102 views
1 answer 95 views
1 answer 102 views
...