Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Remove Item from Array by Value</title> </head> <body> <script> // Sample array var array = ["red", "green", "blue"]; // Item to remove var item = "green"; // Get the index of the item var index = array.indexOf(item); // Check to see if the item exists in the array, if exists then remove it if(index !== -1) { array.splice(index, 1); } document.write(JSON.stringify(array)); // Prints: ["red","blue"] </script> </body> </html>