How to remove all items from specific index in TypeScript

2 Answers

0 votes
const arr = ['typescript', 'php', 'python', 'c', 'c#', 'c++', 'go', 'css', 'java'];
   
const index = 4;
  
arr.splice(index);
   
console.log(arr); 
   
   
   
   
/*
run:

["typescript", "php", "python", "c"] 
   
*/

 



answered Jul 7, 2022 by avibootz
0 votes
const arr = ['typescript', 'php', 'python', 'c', 'c#', 'c++', 'go', 'css', 'java'];
   
const index = 4;
  
arr.length = index;
   
console.log(arr); 
   
   
   
   
/*
run:

["typescript", "php", "python", "c"] 
   
*/

 



answered Jul 7, 2022 by avibootz

Related questions

1 answer 128 views
2 answers 166 views
2 answers 154 views
1 answer 117 views
1 answer 109 views
1 answer 116 views
...