How to remove all items from specific index in JavaScript

2 Answers

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

["javascript", "php", "python"]
   
*/

 



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

["javascript", "php", "python"]
   
*/

 



answered Jul 7, 2022 by avibootz

Related questions

1 answer 109 views
2 answers 165 views
2 answers 146 views
1 answer 116 views
1 answer 127 views
...