title: sorting of array manually in javascript
body: <p>I have an array of strings like below.</p>
  
  <pre><code>ABC
  QRS
  DEF
  HIJ
  TUV
  KLM
  NOP
  </code></pre>
  
  <p>I need to sort this array in javascript in alphabetical order, except for few values which is already known. ie I need DEF and NOP comes in the first 2 positions and sort rest of the array alphabetically in ascending order. Here is what I've written to sort the entire array in alphabetical order, now I need the 2 values in the first 2 positions.</p>
  
  <pre><code>array.sort(function(a,b){return ((a &lt; b) ? -1 : (a &gt; b) ? 1 : 0)});
  </code></pre>
  
  <p>Expected result.</p>
  
  <pre><code>DEF
  NOP
  ABC
  HIJ
  KLM
  QRS
  TUV
  </code></pre>
  
  <p>The contents of the array is dynamic, so if the array has DEF or NOP, then those should be on top, if else, it should be sorted alphabetically. Whats the best way to approach this?</p>