
To remove a specific item from an array in JavaScript, you can use the `splice()` method. The `splice()` method modifies the original array and returns the removed elements as a new array.
Here’s an example:
const fruits = [‘apple’, ‘banana’, ‘orange’, ‘mango’];
// Remove the second item (index 1)
const removedFruits = fruits.splice(1, 1);
console.log(fruits); // Output: [“apple”, “orange”, “mango”]
console.log(removedFruits); // Output: [“banana”]
In the example above, we first define an array of fruits. We then use the `splice()` method to remove the second item (index 1) from the array. The first argument of the `splice()` method is the index at which to start changing the array, and the second argument is the number of elements to remove. In this case, we want to remove only one element, so we pass 1 as the second argument. The `splice()` method returns an array of the removed elements, which we store in the `removedFruits` variable. Finally, we log the updated `fruits` array and the `removedFruits` array to verify that the element has been removed.
