title: Sort objects in an array alphabetically based on one property
body: <p>I know that there is a similar question, <a href="https://stackoverflow.com/questions/8900732/javascript-sort-objects-in-an-array-alphabetically-on-one-property-of-the-arra/8900922">Javascript - sort objects in an array alphabetically on one property of the array</a>, but when I run step by step using this method it jumps over the sort.</p>
  
  <p>I have an array of objects which looks like this in console:</p>
  
  <pre><code>0:{id: "3645256536754", name: "john", description: "man", children: Array(0)}
  1:{id: "8672092533958", name: "alex", description: "man", children: Array(2)}
  </code></pre>
  
  <p>I must do a <code>forEach</code> on it but before I must be sure that it is in alphabetical order based on the <code>name</code> property.</p>
  
  <p>I did it like this:</p>
  
  <pre><code>myArray.sort(function (a, b) {
      var textA = a.name.toUpperCase();
      var textB = b.name.toUpperCase();
      return (textA &lt; textB) ? -1 : (textA &gt; textB) ? 1 : 0;
  })
  </code></pre>
  
  <p>When I run it step by step it jumps over this piece of code, I don't know why. Any suggestions?</p>