title: Alphabet increment function by index number in js
body: <p>I am trying to merge an array of objects into a single object and on the object key, I want the alphabet letters.</p>
  <p>I have created a function <strong>incrementLetter</strong> it will take the index number and from the index number it will return the alphabet, the issue is the alphabet is 26 letters if the index is 27 then I want it will return <strong>AA</strong> if 28 then <strong>AB</strong> etc.. but after 26 indexes I am getting only <strong>AA</strong> the function doesn't return <strong>AB</strong> if the index is 27 or 28.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function incrementLetter(charIndex) {
    const letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    let value = letter.charAt(charIndex);
    let carry = 1;
    let res = "";
  
    for (let i = value.length - 1; i &gt;= 0; i--) {
      let char = value.toUpperCase().charCodeAt(i);
  
      char += carry;
  
      if (char &gt; 90) {
        char = 65;
        carry = 1;
      } else {
        carry = 0;
      }
  
      res = String.fromCharCode(char) + res;
  
      if (!carry) {
        res = value.substring(0, i) + res;
        break;
      }
    }
  
    if (carry) {
      res = "A" + res;
    }
  
    return res;
  }
  
  const dataSource =[{"column_name":"id"},{"column_name":"group_name"},{"column_name":"date_lol"},{"column_name":"aaaasdccc"},{"column_name":"created_table_at"},{"column_name":"test_bro"},{"column_name":"ddddd"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"},{"column_name":"ddddda"}]
  
  
    const addKeyLetter = (data) =&gt; {
      const mapped = data.map((item, i) =&gt; ({
        [incrementLetter(i -1)]: item.column_name,
      }));
      const object = Object.assign({}, ...mapped);
     console.log(object);
    };
    addKeyLetter(dataSource);</code></pre>
  </div>
  </div>
  </p>
  <p>Expected output</p>
  <pre><code>{
    &quot;A&quot;: &quot;ID&quot;,
    &quot;B&quot;: &quot;group_name&quot;,
    &quot;C&quot;: &quot;date_lol&quot;,
    &quot;D&quot;: &quot;aaaasdccc&quot;,
    &quot;E&quot;: &quot;created_table_at&quot;,
    &quot;F&quot;: &quot;test_bro&quot;,
    &quot;G&quot;: &quot;ddddd&quot;,
    &quot;H&quot;: &quot;ddddda&quot;,
    &quot;I&quot;: &quot;ddddda&quot;,
    &quot;J&quot;: &quot;ddddda&quot;,
    &quot;K&quot;: &quot;ddddda&quot;,
    &quot;L&quot;: &quot;ddddda&quot;,
    &quot;M&quot;: &quot;ddddda&quot;,
    &quot;N&quot;: &quot;ddddda&quot;,
    &quot;O&quot;: &quot;ddddda&quot;,
    &quot;P&quot;: &quot;ddddda&quot;,
    &quot;Q&quot;: &quot;ddddda&quot;,
    &quot;R&quot;: &quot;ddddda&quot;,
    &quot;S&quot;: &quot;ddddda&quot;,
    &quot;T&quot;: &quot;ddddda&quot;,
    &quot;U&quot;: &quot;ddddda&quot;,
    &quot;V&quot;: &quot;ddddda&quot;,
    &quot;W&quot;: &quot;ddddda&quot;,
    &quot;X&quot;: &quot;ddddda&quot;,
    &quot;Y&quot;: &quot;ddddda&quot;,
    &quot;Z&quot;: &quot;ddddda&quot;,
    &quot;AA&quot;: &quot;ddddda&quot;,
    &quot;AB&quot;: &quot;dddda&quot;
  }
  </code></pre>