JS中string方法中常用方法之一:String.prototype.charAt()
来源:互联网 发布:好莱坞爱情电影知乎 编辑:程序博客网 时间:2024/06/05 15:55
String.prototype.charAt()返回字符串中指定位置的字符。
语法:str.charAt(index)(index 是0 到 字符串长度-1 的一个整数)
例子:输出字符串中不同位置的字符
//下例输出字符串 "Brave new world" 不同位置处的字符
var anyString = "Brave new world";
console.log("The character at index 0 is '" + anyString.charAt(0) + "'");
console.log("The character at index 1 is '" + anyString.charAt(1) + "'");
console.log("The character at index 2 is '" + anyString.charAt(2) + "'");
console.log("The character at index 3 is '" + anyString.charAt(3) + "'");
console.log("The character at index 4 is '" + anyString.charAt(4) + "'");
console.log("The character at index 999 is '" + anyString.charAt(999) + "'");
//上面代码的输出为:
The character at index 0 is 'B'
The character at index 1 is 'r'
The character at index 2 is 'a'
The character at index 3 is 'v'
The character at index 4 is 'e'
The character at index 999 is ''
语法:str.charAt(index)(index 是0 到 字符串长度-1 的一个整数)
例子:输出字符串中不同位置的字符
//下例输出字符串 "Brave new world" 不同位置处的字符
var anyString = "Brave new world";
console.log("The character at index 0 is '" + anyString.charAt(0) + "'");
console.log("The character at index 1 is '" + anyString.charAt(1) + "'");
console.log("The character at index 2 is '" + anyString.charAt(2) + "'");
console.log("The character at index 3 is '" + anyString.charAt(3) + "'");
console.log("The character at index 4 is '" + anyString.charAt(4) + "'");
console.log("The character at index 999 is '" + anyString.charAt(999) + "'");
//上面代码的输出为:
The character at index 0 is 'B'
The character at index 1 is 'r'
The character at index 2 is 'a'
The character at index 3 is 'v'
The character at index 4 is 'e'
The character at index 999 is ''
0 0
- JS中string方法中常用方法之一:String.prototype.charAt()
- JS中string方法中常用方法之十二:String.prototype.toLowerCase()和String.prototype.toUpperCase()
- JS中string方法中常用方法之二:String.prototype.concat()
- JS中string方法中常用方法之三:String.prototype.charCodeAt()
- JS中string方法中常用方法之五:String.prototype.slice()
- JS中string方法中常用方法之六:String.prototype.substring()
- JS中string方法中常用方法之七:String.prototype.search()
- JS中string方法中常用方法之八:String.prototype.indexOf()
- JS中string方法中常用方法之九:String.prototype.match()
- JS中string方法中常用方法之十:String.prototype.toLocaleLowerCase()
- JS中string方法中常用方法之十一:String.prototype.toLocaleUpperCase()
- JS中string方法中常用方法之十三:String.prototype.replace()
- Java String charAt()方法
- javascript中 string的charAt()和charCodeAt()方法
- js中string对象的常用方法
- JS中String对象常用的方法
- String charAt()、charCodeAt()、fromCharCode()方法
- java.lang.String.charAt() 方法
- 替换空格
- Java系列笔记(3) - Java 内存区域和GC机制
- Missing Number解题报告
- 网口扫盲三:以太网芯片MAC和PHY的关系
- 学习笔记1—CSS盒模型
- JS中string方法中常用方法之一:String.prototype.charAt()
- Ajax的url与form表单的Action冲突问题
- Git-源码管理工具
- 竞争网络
- 指针2
- 不使用库函数strcat(),自行编程实现str_append()功能
- 51nod oj 1043 幸运号码 【数位DP】
- lvm恢复数据
- 4.跟我学solr---SolrRequestHandler详解