In JavaScript, the charAt() method can be used to obtain and return the character at the specified position. The syntax is "string.charAt(index)"; the parameter "index" is used to specify the position of the character in the string. It is a numeric value, ranging from "0~string length-1".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
The charAt() method returns the character at the specified position. (Note: The first character position is 0, the second character position is 1, and so on.)
Syntax:
string.charAt(index)
index: required parameters; A number that represents a position in a string, that is, the position of a character in the string.
Return value: String type, returns the character at the specified position.
Example: Return the last character in the string
var str = "HELLO WORLD"; var n = str.charAt(str.length-1);
Rendering:
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to use charAt() in javascript. For more information, please follow other related articles on the PHP Chinese website!