To remove a specific element from an array in JavaScript, you can use the `splice` method or create a new array excluding the element to be removed.
In this example,
let numbers = [1, 2, 3, 4, 5];
let indexToRemove = numbers.indexOf(3);
numbers.splice(indexToRemove, 1);
console.log(`Array after removing 3: ${numbers}`);
Array after removing 3: 1,2,4,5
In this example,
let colors = ['red', 'green', 'blue', 'yellow'];
let elementToRemove = 'green';
let newArray = colors.filter(color => color !== elementToRemove);
console.log(`Array after removing ${elementToRemove}: ${newArray}`);
Array after removing green: red,blue,yellow
In this tutorial, we learned How to Remove Specific Element from an Array in JavaScript language with well detailed examples.