How to remove an item from an array by index in JavaScript

1 Answer

0 votes
const arr = ["javascript", "php", "c++", "python", "c"];
 
let index = 1;
let item = arr.splice(index, 1);
 
arr.forEach(function(item, index, array) {
    console.log(item + " " + index);
});
 
 
 
 
/*
run:
       
"javascript 0"
"c++ 1"
"python 2"
"c 3"
     
*/

 



answered Nov 2, 2019 by avibootz
edited Mar 1, 2023 by avibootz

Related questions

1 answer 215 views
1 answer 198 views
1 answer 144 views
1 answer 176 views
1 answer 196 views
1 answer 155 views
1 answer 128 views
128 views asked Feb 28, 2023 by avibootz
...