title: How to sort strings in JavaScript
body: <p>I have a list of objects I wish to sort based on a field <code>attr</code> of type string. I tried using <code>-</code></p>
  
  <pre><code>list.sort(function (a, b) {
      return a.attr - b.attr
  })
  </code></pre>
  
  <p>but found that <code>-</code> doesn't appear to work with strings in JavaScript. How can I sort a list of objects based on an attribute with type string?</p>