Sort in Array:- Geniusofstudent

  • The sort() method is used to sort the items of an array.
  • The order of the sorting are either ascending or descending and either alphabetic or numeric.
Code:-


  1. <!DOCTYPE html> 
  2. <html> 
  3.  
  4. <head> 
  5.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  6. </head> 
  7.  
  8. <body> 
  9.  
  10.  <h1>sort()</h1> 
  11.  <h1>ar = ["G","X","Q","A","Z","B"]</h1> 
  12.  
  13.  <input type="button" onclick="ar_sr();" value="Call Array Sort"> 
  14.  
  15.  <script> 
  16.   function ar_sr() 
  17.   { 
  18.  
  19.    var ar = ["G", "X", "Q", "A", "Z", "B"]; 
  20.  
  21.    alert("Actual : " + ar); 
  22.    alert("Sorted Array : " + ar.sort()); 
  23.  
  24.   } 
  25.  </script> 
  26.  
  27. </body> 
  28.  
  29. </html>
Sort in Array:- Geniusofstudent  Sort in Array:- Geniusofstudent Reviewed by Network security on August 06, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.