title: Sorting an Array of JavaScript Objects a Specific Order (using existing function)
body: <p>Given an array of objects:</p>
  
  <pre>
  {
      key: "a",
      value: 42
  },
  {
      key: "d",
      value: 28
  },
  {
      key: "c",
      value: 92
  },
  {
      key: "b",
      value: 87
  }
  </pre>
  
  <p>and an array of keys:</p>
  
  <pre><code>["c", "a", "b", "d"]
  </code></pre>
  
  <p>Is there a ECMAScript function or a 3rd-party JavaScript library that lets you sort - <strong>in one line/function call</strong> - the first array of objects, to <strong>match the order of the keys</strong> specified in the second array, such that the result is:</p>
  
  <pre>
  {
      key: "c",
      value: 92
  },
  {
      key: "a",
      value: 42
  },
  {
      key: "b",
      value: 87
  },
  {
      key: "d",
      value: 28
  }
  </pre>
  
  <p>Other questions that provide a function or algorithm:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/13304543/javascript-sort-array-based-on-another-array">Javascript - sort array based on another array - Stack Overflow</a></li>
  <li><a href="https://stackoverflow.com/questions/9755889/how-do-i-sort-an-array-of-objects-based-on-the-ordering-of-another-array">javascript - How do I sort an array of objects based on the ordering of another array? - Stack Overflow</a></li>
  </ul>
  
  <p>Similar/related questions:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/355550/sorting-an-array-of-objects-in-php-in-a-specific-order">Sorting an Array of Objects in PHP In a Specific Order</a></li>
  <li><a href="https://stackoverflow.com/questions/2122062/sort-array-of-objects">php - Sort array of objects</a></li>
  </ul>