title: Alphabetize a list using JS or jQuery
body: <p>I'm trying to take the contents of a list, that is not in alphabetical order, then by adding each item to an array, sort them into alphabetical order and insert them back into the list in alphabetical order. </p>
  
  <p>Plain language: I need to alphabetize a list using JS or jQuery. </p>
  
  <p>Here's what I have. I just can't figure out how to insert the contents of the array in back into the list. </p>
  
  <p>Thank you all in advance :)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var sectors = [];
  $("li").each(function() { sectors.push($(this).text()) });
  sectors.sort();
  console.log(sectors);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;ul&gt;
    &lt;li id="alphabet"&gt;B&lt;/li&gt;
    &lt;li id="alphabet"&gt;C&lt;/li&gt;
    &lt;li id="alphabet"&gt;A&lt;/li&gt;
  &lt;/ul&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://jsfiddle.net/stu16396/" rel="nofollow">https://jsfiddle.net/stu16396/</a></p>