Sort number and number with letters in Javascript - Javascript Data Type

Javascript examples for Data Type:Number

Description

Sort number and number with letters in Javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body>  
      <p>Click the button to sort the array.</p> 
      <button onclick="myFunction()">Try it</button> 
      <p id="demo"></p> 
      <script>
var array = [101,102,103,"101a","101b",104,"103a","102a",'1X','2E'];

document.getElementById("demo").innerHTML = array;

function myFunction() {//ww  w .  j a  v  a 2 s. c  o m
    array.sort();
    document.getElementById("demo").innerHTML = array;
}

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

Related Tutorials