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 206 views
1 answer 189 views
1 answer 137 views
1 answer 166 views
1 answer 184 views
1 answer 147 views
1 answer 117 views
117 views asked Feb 28, 2023 by avibootz
...