title: reverse json javascript
body: <p>Is there an inexpensive way to reverse:</p>
  
  <pre><code>{
      "10": "..."
      "11": "...",
      "12": "...",
      "13": "...",
      "14": "...",
  }
  </code></pre>
  
  <p>so that I get:</p>
  
  <pre><code>{
      "14": "...",
      "13": "...",
      "12": "..."
      "11": "...",
      "10": "...",
  }
  </code></pre>
  
  <p>reverse() doesn't seem to work on json objects. The only way I can think of is to loop through all the elements and create an array. feels like there should be a better way.</p>
  
  <p><strong>Edit: thanks for all the help UPDATE:</strong></p>
  
  <p>What about let's say if each key has chronological data. When I use $.each on the object, it runs through the objects from top to bottom, I didn't realize that was unreliable.</p>
  
  <p>Here's what I'm trying to do:</p>
  
  <pre><code>$.each(object, function (key, value) {
    function foo (key, value);
  });
  </code></pre>
  
  <p>I want to not run foo on all but the last 3 pairs, that is I only want to use the last 3 pairs. I figured if I can reverse them I can just run the first three and stop.</p>
  
  <p>Is there any way I can just do the last 3? If the last 3 ordering is unreliable, is there a safer way to grab the last 3. The last 3 will have the largest numerical keys.</p>
  
  <p>Thanks.</p>
  
  <p>Edit 2:
  I'm basically deciding finally to do the manipulations on the server side. I'm reorganizing my database so that the relevant subdocuments are now full on documents that could be queried with mongodb. Thanks.</p>