How to delete an array element in TypeScript

2 Answers

0 votes
let arr: string[] = ["TypeScript", "PHP", "C", "Python"];
   
delete arr[0]; // Change the element to undefined
   
console.log(arr);
   
   
/*
run:
  
[, "PHP", "C", "Python"]
   
*/

 



answered Apr 12, 2025 by avibootz
0 votes
let arr: string[] = ["TypeScript", "PHP", "C", "Python"];
   
arr.splice(0, 1)
   
console.log(arr);
   
   
/*
run:
  
["PHP", "C", "Python"] 
   
*/

 



answered Apr 12, 2025 by avibootz
...