MV Splice specific value in array

I am making a trail game.

I added my character ID to an array.

Example: Var1 = [2,3,4,5]

I created a random chance system to splice a character to then give a state. When player is no longer affected by state I then push the ID back to the array. If they die within the state then obviously that value dies with them. But, one thing I am running into is if they die while not affected in the state. Let’s say the player ID is 3 and their HP drops to zero and die. Is there a way to then splice that ID from the array?
[2,3,4,5] - [3] => [2,4,5]

that should be basic array operation, valid for any language.
[2,3,4,5] - [3] => [2,4,5]

that should be basic array operation, valid for any language.
You can't do that in javascript as far as I know.
You can remove a specific element from an array by find its index in the array and use splice method (https://www.w3schools.com/jsref/jsref_splice.asp)
For example:
Code:
var newArray = array.splice(array.indexOf(element), 1)
Code:
var newArray = array.splice(array.indexOf(element), 1)
what if there's two identical elements?
what if there's two identical elements?
In that case we have to use a while loop to check.
Code:
var array = [1, 3, 2, 3, 5]
var element = 3;
while (true) {
    const index = array.indexOf(element);
    // Break the loop if can't find the element in the array.
    if (index === -1) break;
    array = array.splice(index, 1);
}
// new array will be [1, 2, 5]
That worked! Thank you so much for your help!
For those who are interested here is the code I used to test the above code:


$gameVariables.setValue(19, [4,7,2,3,4,1]);
var element = 1;
while (true) {
const index = $gameVariables.value(19).indexOf(element);
// Break the loop if can't find the element in the array.
if (index === -1) break;
$gameVariables.value(19).splice(index, 1);

// new array will be [4,7,2,3,4]

Original thread: https://forums.rpgmakerweb.com/threads/splice-specific-value-in-array.149305/