title: Javascript sort function. Sort by First then by Second
body: <p>I have an array of objects to sort. Each object has two parameters: Strength and Name</p>
  
  <pre><code>objects = []
  object[0] = {strength: 3, name: "Leo"}
  object[1] = {strength: 3, name: "Mike"}
  </code></pre>
  
  <p>I want to sort first by Strength and then by name alphabetically. I am using the following code to sort by the first parameter. How do I sort then by the second? </p>
  
  <pre><code>function sortF(ob1,ob2) {
    if (ob1.strength &gt; ob2.strength) {return 1}
    else if (ob1.strength &lt; ob2.strength){return -1}
    return 0;
  };
  </code></pre>
  
  <p>Thanks for your help.</p>
  
  <p>(I am using <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort" rel="noreferrer">Array.sort()</a> with the aforementioned sortF as the sort comparison function passed into it.)</p>