title: Sort Keys in Javascript Object
body: <p>I have a Javascript Object that contains a mix of property types including simple strings, objects, arrays of objects... and so on.</p>
  
  <p>I would like to sort the keys following this rule: </p>
  
  <p>'Simple properties like strings or numbers appears always before more complex properties that contains arrays or objects'</p>
  
  <p>I wrote the following function, that almost do what I am trying to achieve, but it converts the arrays into objects. This is not the desired behaviour. Can anybody help me to create a function that keep arrays as arrays and at the same time it sorts the objects inside arrays?</p>
  
  <pre><code>function sort(object){
      if (typeof object != "object" )
          return object;
      var keys = Object.keys(object);
      keys.sort(function(a,b){
              if (typeof(object[a])!== 'object') { return -1 } else { return 1 }
          });
  </code></pre>
  
  <p>Working jsfiddle:</p>
  
  <p><a href="http://jsfiddle.net/u01mn2py/3/" rel="nofollow">http://jsfiddle.net/u01mn2py/3/</a></p>
  
  <p>Kind Regards</p>