JavaScript method to delete array elements

  • 2020-05-17 04:50:34
  • OfStack

This example shows how JavaScript can delete an array element. Share with you for your reference. The specific analysis is as follows:

Array elements can be deleted from JS via delete, but the size of the array does not change after the deletion

<script type="text/javascript">
var days = ["Sunday","Monday","Tuesday","Wednesday",
document.write("Number of days:"+days.length);
  delete days[4];
document.write("<br />Number of days:"+days.length);

The output

Number of days:7
Number of days:7

I hope this article is helpful to you in javascript programming.

Related articles: