How do I remove a particular element from an array in JavaScript?

I have an array of integers, and I’m using the .push() method to add elements to it.

Is there a simple way to remove a specific element from an array? The equivalent of something like array.remove(int);.

I have to use core JavaScript – no frameworks are allowed.

First, find the index of the element you want to remove:

Note: browser support for indexOf is limited; it is not supported in Internet Explorer 7 and 8.

Then remove it with splice:

The second parameter of splice is the number of elements to remove. Note that splice modifies the array in place and returns a new array containing the elements that have been removed.

If you need indexOf in an unsupported browser, try the following polyfill. Find more info about this polyfill here.