JavaScript Tutorial/String/charAt
Версия от 18:52, 25 мая 2010; (обсуждение)
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)