Home > DeveloperSection > Interviews > How to delete an array entry using JavaScript?

Posted on    March-18-2011 12:00 AM

 JavaScript JavaScript 
Ratings:
 1 Answer(s)
  1238  View(s)
Rate this:

Amit Singh

Total Post:565

Points:2825
Posted on    March-18-2011 12:00 AM

The "delete" operator removes an array element in JavaScript , but oddly does not change the size of the array.
For Example:
<script type="text/javascript">
var days = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"];
document.write("Number of days:"+days.length); delete days[4]);
document.write("<br />Number of days:"+days.length);
</script>

Output:
Number of days:7
Number of days:7

Don't want to miss updates? Please click the below button!

Follow MindStick