title: I just want to sort my words from array alphabetically by 1st letter and then by 2nd letter according to my given pattern which matched by 1st letter
body: <p>♦ pattern:
  e,b,c,d,i,f,g,h,o,j,k,l,m,n,u,p,q,r,s,t,a,v,w,x,y,z</p>
  <p>I want to sort my words from arr alphabetically by 1st letter and then by 2nd letter of a similar word matched by 1st letter according to my given pattern.</p>
  <p><strong>['aobcdh', 'aibcdh', 'aabcdh', 'aacbdh', 'cfghjd', 'cighjd']</strong></p>
  <p><strong>♦ output should be:</strong></p>
  <blockquote>
  <p>['aibcdh', 'aobcdh', 'aabcdh', 'aacbdh', 'cighjd', 'cfghjd'  ]</p>
  </blockquote>
  <p><strong>♦ or:</strong>
  <em>aibcdh
  aobcdh
  aabcdh
  aacbdh
  cighjd
  cfghjd</em></p>
  <blockquote>
  <p>My Code here:</p>
  </blockquote>
  <pre><code>    let pattern = ['e', 'b', 'c', 'd', 'i', 'f', 'g', 'h', 'o', 'j', 'k', 'l', 'm', 'n', 'u', 'p', 'q', 'r', 's', 't', 'a', 'v', 'w', 'x', 'y', 'z']
  let arr = ['aobcdh', 'aibcdh', 'aabcdh', 'aacbdh', 'cfghjd', 'cighjd']
  let arrSorted = arr.sort() //Natural sorting
  console.log(arrSorted)
  
  // output in array
  const newArr = arrSorted.sort((a, b) =&gt; pattern.indexOf(a[1]) - pattern.indexOf(b[1]))
  console.log(newArr) //Sorted by its 2nd character with given pattern
  
  // single output without array
  for (let i = 0; i &lt; pattern.length; i++) {
      for (let j = 0; j &lt; arrSorted.length; j++) {
          if (pattern[i] === arrSorted[j][1]) {
              console.log(arrSorted[j]) //Sorted by its 2nd character with given pattern
          }
      }
  }
  </code></pre>