JavaScript Tutorial/String/charAt
Compare the char value
<HTML>
<BODY>
<SCRIPT language="JavaScript">
<!--
var the_name="abc";
first_char=the_name.charAt(0);
if (first_char=="S") {
document.write(the_name);
} else {
document.write(first_char);
}
//-->
</SCRIPT>
</BODY>
</HTML>
Get char in a string by index
<HTML>
<BODY>
<SCRIPT language="JavaScript">
<!--
var the_name="abc";
first_char=the_name.charAt(0);
if (first_char=="S") {
document.write(the_name);
} else {
document.write(first_char);
}
//-->
</SCRIPT>
</BODY>
</HTML>
String.charAt()
Syntax
string.charAt(num)