Removing an element from a JavaScript array by index number is easy. You can use the JavaScript built-in method splice(). The example is given below.

<script>
  const myArray = ['Red', 'Green' , 'Blue', 'Yellow'];   
      myArray.splice(2,1)
      console.log(myArray)
</script>

Remove element from JavaScript array by value #

But in this article, I will talk about how to remove an element from a JavaScript array by value.

You can use the filter() method which creates a new version of your original JavaScript array without including any item whose condition evaluates false according to your custom function's logic :

<script>
 const myArray = ['Red', 'Green' , 'Blue', 'Yellow'];   
 const newArray = myArray.filter((element) => element !== 'Blue');    
 console.log(newArray)
</script>