Here we will discuss how we can remove particular element from an array using JavaScript in asp.net. We can use the splice function to remove the element.
Also you can check out:
- How to get substring from string using jQuery in asp.net?
- How to open hyperlink in new tab using jQuery or JavaScript?
- How to validate user input for mobile number using Regular Expression in Javascript?
Once you will click on the button, it will show the length like below:
Hope this will be helpful.
Also you can check out:
- How to get substring from string using jQuery in asp.net?
- How to open hyperlink in new tab using jQuery or JavaScript?
- How to validate user input for mobile number using Regular Expression in Javascript?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnGetString").on("click", function () {
var array = [1, 2, 3];
var index = array.indexOf(2);
if (index > -1) {
array.splice(index, 1);
}
alert(array.length);
});
});
</script>
<br />
<div class="row">
<div class="col-md-4">
<input type="button" id="btnGetString" value="Remove Element From
Array"
/><br />
</div>
</div>Once you will click on the button, it will show the length like below:
Hope this will be helpful.