Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 Posts

    iterate through alphabet in Javascript

    How do i iterate from A-Z in javascript?

    var column = A;
    column ++;

    And now column should be B. Is that possible? Thanks
    ---------
    Client / Server Side Programmer II

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    I do not know if there is a way as you have asked but I have this solution, try it:

    Code:
    function iterateAlphabet()
    	{
    	   var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	   for(var i=0; i<str.length; i++)
    	   {
    	      var nextChar = str.charAt(i);
    	      alert(nextChar)
    	   }
    	}

  • #3
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    The above solution is probably the easiest.

    Alternatively, you could do it with charcodes:
    Code:
    var charCodeRange = {
    	start: 65,
    	end: 90
    }
    for (var cc = charCodeRange.start; cc <= charCodeRange.end; cc++) {
    	alert(String.fromCharCode(cc));
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •