How to remove items from array in JavaScript
How to remove items from array in JavaScript - Follow link https://code2care.org/q/remove-items-from-javascript-array
HTML
<html>
<head>
<title>How to remove items from array in JavaScript</title>
</head>
<body>
<h1>How to remove items from array in JavaScript</h1>
Follow link <a href="https://code2care.org/q/remove-items-from-javascript-array">https://code2care.org/q/remove-items-from-javascript-array</a>
<br/><br/>
Check Console logs
</body>
</html>
JavaScript
//Step 1: Note we have 5 elements/items in the array fruits
var fruits = ['orange', 'mango', 'banana', 'grapes', 'plum'];
//Lets print the array in console
console.log("Before removal: "+fruits);
//Step 2: Now lets get index of banana element that we want to remove
const idx = fruits.indexOf('banana');
//Step 3: Lets slice the element out
if(idx > -1)
fruits.splice(idx, 1);
//Step 4: Let's print the array again in console to see the result.
console.log("After removal: "+fruits);