title: How to sort javascript object key in ASC
body: <p>I want to sort object keys in ASC .My keys is string and number so try with sort is not solve .</p>
  
  <pre><code>//sorting number function
  function sortNum(a,b) {
      return a - b;
  }
  let obj = {key10:10,key2:2,key5:5,key1:1};
  let ordered = {};
  Object.keys(obj).sort().forEach(function(key,v){
      ordered[key] = v;
  });
  console.log(ordered); //{key1: 1, key10: 10, key2: 2, key5: 5}
  //try with sort number function
  //Object.keys(obj).sort(sortNum).forEach(function(key){
  //ordered[key] = obj[key];
  //});
  //console.log(ordered); -&gt; {key10: 10, key2: 2, key5: 5, key1: 1}
  </code></pre>
  
  <blockquote>
    <p>Expected =>  <code>{key1: 1, key2: 2, key5: 5, key10: 10}</code></p>
  </blockquote>