简介JavaScript中charAt()方法的使用


这个方法返回从指定索引的字符。

字符串中的字符进行索引从左向右。第一个字符的索引是0,并且在一个叫 stringName字符串的最后一个字符的索引是stringName.length- 1。
语法

string.charAt(index);

下面是参数的详细信息:

index: 介于0和1比串的长度以下的整数。

返回值:

返回从指定索引的字符。
例子:

<html>
<head>
<title>JavaScript String charAt() Method</title>
</head>
<body>
<script type="text/javascript">
  var str = new String( "This is string" );
  document.writeln("str.charAt(0) is:" + str.charAt(0)); 
  document.writeln("<br />str.charAt(1) is:" + str.charAt(1)); 
  document.writeln("<br />str.charAt(2) is:" + str.charAt(2)); 
  document.writeln("<br />str.charAt(3) is:" + str.charAt(3)); 
  document.writeln("<br />str.charAt(4) is:" + str.charAt(4)); 
  document.writeln("<br />str.charAt(5) is:" + str.charAt(5)); 
</script>
</body>
</html>

这将产生以下结果:

str.charAt(0) is:T 
str.charAt(1) is:h 
str.charAt(2) is:i 
str.charAt(3) is:s 
str.charAt(4) is: 
str.charAt(5) is:i 

JavaSacript中charCodeAt()方法的使用详解
该方法返回一个数字,表示给定索引处的字符的Unicode值。Unicode码点范围为0到1114111。前128个Unicode码点的ASCII字符编码的直接匹配。charCodeAt()将始终返回

JavaScript中的lastIndexOf()方法使用详解
此方法调用String对象之内返回索引指定的值最后一次出现,开始搜索在的fromIndex或如果没有找到该值则返回-1。语法string.lastIndexOf(searchValue[,fromIndex])下

JavaScript中使用concat()方法拼接字符串的教程
这种方法将两个或多个字符串,并返回一个新的单字符串。语法string.concat(string2,string3[,...,stringN]);下面是参数的详细信息:string2...stringN:这些是要连接