...

View Full Version : iterate through alphabet in Javascript



ynotlim
07-24-2009, 08:56 PM
How do i iterate from A-Z in javascript?

var column = A;
column ++;

And now column should be B. Is that possible? Thanks

ckeyrouz
07-24-2009, 09:16 PM
I do not know if there is a way as you have asked but I have this solution, try it:


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

venegal
07-24-2009, 09:21 PM
The above solution is probably the easiest.

Alternatively, you could do it with charcodes:


var charCodeRange = {
start: 65,
end: 90
}
for (var cc = charCodeRange.start; cc <= charCodeRange.end; cc++) {
alert(String.fromCharCode(cc));
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum