JavaScript -> Objekty -> String -> metóda charAt
Syntax
jmeno_string.charAt(index)
Popis
Príkaz jazyka JavaScript
Vraci znak specifikovaneho index.
- jmeno_string je libovolny retezec nebo vlastnost existujiciho objektu.
- index je libovolne cele cislo v intervalu 0 az jmeno_string.length - 1, nebo vlastnost existujiciho objektu.
Znaky v retezci jsou indexovany zleva doprava. Index prvniho znaku je 0 a index posledniho znaku je jmeno_string.length - 1. Pokud je index, ktery dosadite, mimo rozsah, JavaScript vraci prazdny retezec.
Príklad
var anyString=
"Brave new world"
document.write("The character at index 0 is " + any
String.charAt(0
))
document.write("<br>The character at index 1 is " + any
String.charAt(1
))
document.write("<br>The character at index 2 is " + any
String.charAt(2
))
document.write("<br>The character at index 3 is " + any
String.charAt(3
))
document.write("<br>The character at index 4 is " + any
String.charAt(4
))
Príklad vypíše:
The character at index 0 is B
The character at index 1 is r
The character at index 2 is a
The character at index 3 is v
The character at index 4 is e