最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2020年05月10日 12:09:46   投稿:goldensun  
這篇文章主要介紹了JavaScript中charAt()方法的使用詳解,是JS入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下

 這個(gè)方法返回從指定索引的字符。

字符串中的字符進(jìn)行索引從左向右。第一個(gè)字符的索引是0,并且在一個(gè)叫 stringName字符串的最后一個(gè)字符的索引是

stringName.length- 1。

語法

string.charAt(index);

參數(shù) 描述
index 必需。表示字符串中某個(gè)位置的數(shù)字,即字符在字符串中的下標(biāo)。

下面是參數(shù)的詳細(xì)信息:

  •     index: 介于0和1比串的長度以下的整數(shù)。

返回值:

返回從指定索引的字符。

提示和注釋

注釋:字符串中第一個(gè)字符的下標(biāo)是 0。如果參數(shù) index 不在 0 與 string.length 之間,該方法將返回一個(gè)空字符串。

實(shí)例

在字符串 "Hello world!" 中,我們將返回位置 1 的字符:

<script type="text/javascript">
var str="Hello world!"
document.write(str.charAt(1))
</script>

以上代碼的輸出是:

e


[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]

例子:

<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>

這將產(chǎn)生以下結(jié)果:

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 

相關(guān)文章

最新評論

苗栗市| 来凤县| 武川县| 乐安县| 玉树县| 双辽市| 盐亭县| 林西县| 社会| 辽阳市| 白朗县| 华池县| 磴口县| 房山区| 呼图壁县| 惠来县| 桃江县| 仪陇县| 宁乡县| 平阳县| 海兴县| 务川| 新河县| 晋宁县| 华亭县| 尉犁县| 武陟县| 马鞍山市| 儋州市| 虎林市| 子长县| 莱阳市| 西藏| 瑞金市| 遵化市| 利川市| 新宾| 新宁县| 武邑县| 汝州市| 自贡市|