Delete in Array:- Geniusofstudent

The delete operator will delete an object or an element from an array. 

Syntax 
delete array_variable[index];

Code:-

<!DOCTYPE html> 
<html> 

<head> 
 <meta name="viewport" content="width=device-width, initial-scale=1"> 
</head> 

<body> 

 <h1>delete</h1> 
 <h2>ar=["red","green","Apricot","Guava"]</h2> 
 <input type="button" onclick="ar_del();" value="Delete array"> 

 <script> 
  function ar_del() 
  { 
   var ar = ["red", "green", "Apricot", "Guava"]; 

   delete ar[1]; //just green value is deleted not index 
   alert(ar); 
  } 
 </script> 

</body> 


</html>
Delete in Array:- Geniusofstudent Delete in Array:- Geniusofstudent Reviewed by Network security on July 27, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.