Suppose, i have an array
const anArray = ['value 1', 'value 2', 'value 3', 'value 4', 'value 5'];
If i want to remove the value 3
from anArray
but don't know the position of that value in the array, how can i remove that?
Note: I'm a beginner in JavaScript
Use indexOf
to get the index, and splice
to delete:
const anArray = ['value 1', 'value 2', 'value 3', 'value 4', 'value 5'];
anArray.splice(anArray.indexOf("value 3"), 1);
console.log(anArray);
.as-console-wrapper { max-height: 100% !important; top: auto; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With