title: JS: loop through strings, find first letter, output as letter group anchor to associated string(s)?
body: <p><strong>Scenario:</strong> I have content that is alphabetically output into a list from a resource library. I need to be able to loop through each element/item (e.g.: department name) in this list and group all starting with 'A' ('B', 'C', 'D', and so on) into its own class for anchor navigation. Then, I need to be able to find which letters were found and create group anchors. </p>
  
  <p><strong>Desired Output:</strong> At the top of the page, there is each letter of the alphabet found that has element(s) with that letter. Clicking on the letter will anchor to a section/div (new class) with all elements of the corresponding letter.</p>
  
  <p><strong>What I've Tried (to find the first letter and create a group):</strong></p>
  
  <pre><code>    for(var i=0; i&lt;input_1.length; i++){ //input_1 is the name of the specific resource library
     var firstChar = input_1[i].charAt(0)
     var newGroup = firstChar + "_input_1";
     if(typeof(window[newGroup]) == 'undefined') window[newGroup] = []; //if var doesn't exist, create it
     window[newGroup].push(input_1[i]);
  }
  A_input_1 = []; //A-letter-specific group
  </code></pre>
  
  <p>I'm beside myself when it comes to creating an anchor from that group to the associated strings. Ideas?</p>