pop up element from specific index in array

Code Example - pop up element from specific index in array

                
                        let items = ['a', 'b', 'c', 'd'];
let index = items.indexOf('a')
let numberOfElementToRemove = 1;
if (index !== -1) { items.splice(index,numberOfElementToRemove)}
                    
                
 

how to remove element from array in javascript

                        
                                var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]
                            
                        
 

remove elemtns from an array with splice

                        
                                var fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
document.getElementById("demo").innerHTML = fruits;

function myFunction() {
  fruits.splice(2, 2);
  document.getElementById("demo").innerHTML = fruits;
}
                            
                        
 

how can i remove a specific item from an array

                        
                                const items = ['a', 'b', 'c', 'd', 'e', 'f']
const i = 2
const filteredItems = items.slice(0, i).concat(items.slice(i + 1, items.length))
// ["a", "b", "d", "e", "f"]