This article mainly introduces the use of JS Charat, the need for friends can refer to the following
eg: Code as follows: <html> <body> <script type= "Text/javascript" > var str= "Hello world!" document.write ("The character is:" + str.charat (0) + "<br/>") document.write ("the second Charac TER is: "+ str.charat (1) +" <br/> ") document.write (" The third character are: "+ Str.charat (2)) </script> </body> </html> Results: the character is:h&nb Sp The second character is:e the third character is:l definitions and usages charAt () method returns the characters at the specified position. Note that JavaScript does not have a character data type that is different from a string type, so the character returned is a string of length 1. Syntax Stringobject.charat (index) parameter Description index required. A number that represents a position in a string, that is, the subscript of a character in a string. Hints and notes NOTE: The subscript for the first character in a string is 0. If the argument index is not between 0 and String.Length, the method returns an empty string. Instance in the string "Hello world!", we will return the character of position 1: code as follows: <script type= "Text/javascript" > var str= "Hello world!" document.write (Str.charat (1)) </script> The output of the code is: e Returns the character at the specified index position. Strobj.charat (index) parameter strobj required option. Any String object or text. index required options. The zero-based index of the desired character. A valid value is a value between 0 and the length of the string minus 1. Description CharAt method returns a character value that is at the specified index position. The index of the first character in the string is 0, the second index is 1, and so on. An index value that is outside the valid range returns an empty string. Examples The following example illustrates the use of the CharAt method: the code as follows: function Charattest (n) { var str = "Abcdefghij KLMNOPQRSTUVWXYZ "; Initializes the variable. VAR S; Reputation variables. s = Str.charat (n-1); //Get the correct characters from the location where the index is n–1. return (s); Returns the character. }