JavaScript string object introduction instance of the charAt method (used to get the character at the specified location)

  • 2020-03-30 04:09:15
  • OfStack

JavaScript charAt method

The charAt method is used to get the character at the specified position from the string. The syntax is as follows:


str_object.charAt( x )

Parameter description:

parameter instructions
str_object String (object) to manipulate
x A necessity. A number that represents a position

Tip: strings are counted from 0.

Instance of the charAt method


<script language="JavaScript">
document.write( "jb51".charAt( 1 ) );
</script>

Run the example and output:


b

Tip: this method returns an empty string if the argument x is not between 0 and the maximum length of the string.


Related articles: