I have an Array as arr =["Apple","Banana","Mango","Banana","Goa","Banana"] These are having Index position as ,0,1,2 if i want to remove Banana Which is having Index as 0 (Zero) how can i remove that particular element.
Asked
Active
Viewed 90 times
0
-
[`splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) it off. – Amadan Feb 18 '22 at 09:20
1 Answers
1
just check out this example. you just need to splice as here I am using array
const array = [2, 5, 9];
console.log(array);
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
document.getElementById("dem").innerHTML = array;
<div id="dem">Hi </div>
ample
const array = [2, 5, 9];
console.log(array);
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
// array = [2, 9]
console.log(array);

ash
- 1,065
- 1
- 5
- 20