i tride to delete element from array with splice just remove the first element code example

Example 1: 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)}

Example 2: remove element from array javascript

let numbers = [1,2,3,4]

// to remove last element
let last_num = numbers.pop();
// numbers will now be [1,2,3]

// to remove first element
let first_num = numbers.shift();
//numbers will now be [2,3]

// to remove at an index
let number_index = 1
let index_num = numbers.splice(number_index,1); //removes 1 element at index 1
//numbers will now be [2]

//these methods will modify the numbers array and return the removed element