title: JS Sort by specific sort order
body: <p>I need to sort my data by a specific order as shown below.</p>
  
  <pre><code>const sortBy = ['b','a','c','e','d']
  const data = ['a','d','e']
  </code></pre>
  
  <p>I know how to sort by asscending/descending</p>
  
  <pre><code>console.log(data.sort((a, b) =&gt; a &gt; b)) //["a", "d", "e"]
  console.log(data.sort((a, b) =&gt; a &lt; b)) //["e", "d", "a"]
  </code></pre>
  
  <p>But is it possible using <code>.sort</code> to sort in a specific order?
  eg below my desired order is <code>sortBy</code></p>
  
  <p>I am currently getting this to work by creating an array of common items between my sort array and my data.</p>
  
  <pre><code>const commonItems = getCommonItemsInArrays(sortBy,data)
  console.log(commonItems.map(item =&gt; item)) //["a", "e", "d"]
  
  function getCommonItemsInArrays(array1,array2){
    return array1.filter(n =&gt; array2.indexOf(n) &gt;= 0)
  }
  </code></pre>
  
  <p>This seems to be working ok but I was wondering if there was a way to handle this via <code>sort</code>?</p>