sort object values in JavaScript when keys are numbers - Javascript Object

Javascript examples for Object:Object Keys

Description

sort object values in JavaScript when keys are numbers

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {/* w w w  . j  a v  a  2 s.  c  om*/
var myId = {};
var ids = [10, 30, 11, 1, 4, 2];
var producers = ['Ford','Rover','BMW','Fiat','Renault','Mitsubishi'];
ids.sort();
ids.map(function(item, index) {
    myId[item] = producers[index];
}, myId);
console.log(myId);
    });

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

Related Tutorials