title: How to Merge sorted Arrays in JavaScript
body: <p>I have three sorted arrays like below  </p>
  
  <pre><code>[{name:"a"}, {name:"b"}, {name:"m"}, {name:"x"}]
  [{name:"a"}, {name:"e"}, {name:"i"}, {name:"o"}]
  [{name:"g"}, {name:"h"}, {name:"m"}, {name:"n"}]
  </code></pre>
  
  <p>Those arrays are sorted based on name property of each object in Array. Here is the method I converted from Java to merge two sorted arrays</p>
  
  <pre><code>function mergeSorted(a, b) {
    var answer = new Array(a.length + b.length), i = 0, j = 0, k = 0;
    while (i &lt; a.length &amp;&amp; j &lt; b.length) {
      if (a[i].name &lt; b[j].name) {
          answer[k] = a[i];
          i++;
      }else {
          answer[k] = b[j];
          j++;
      }
      k++;
    }
    while (i &lt; a.length) {
      answer[k] = a[i];
      i++;
      k++;
    }
    while (j &lt; b.length) {
      answer[k] = b[j];
      j++;
      k++;
    }
    return answer;
  }
  </code></pre>
  
  <p>Here is the working fiddle with two arrays <a href="http://jsfiddle.net/euRn5/" rel="noreferrer">http://jsfiddle.net/euRn5/</a>. <b>What is the best approach to achieve the same with n number of Arrays, the thought I have in my mind currently is take one by one, merge it with previously merged till the last item, like n += i stuff. Is this a best approach?  </b></p>