Sunday, April 13, 2008

How To Sort Numbers Using JavaScript

<html>
     <head>
           <title>
                Sorting Number Using JavaScript
           </title>
                 <script type="text/JavaScript" language="JavaScript">

                   
 Array.prototype.SrtNum = function()
                   {
                          return this.sort( function (a,b) { return a-b; } );
                   }


                   var arr = [5,9,1,10,8,4,2,7,3];
                   document.write("Before Sorting :"+arr+"<br />After                    Sorting :"+arr.SrtNum());
                   alert(arr=arr.SrtNum());

                     </script>
               
<head>
          <body>
     </body>
</html>

Program Demo



No comments:

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.