提取字符串字符
这是两个提取字符串字符的安全方法:
- charAt(position)
charCodeAt(position)
charAt() 方法
charAt()
方法返回字符串中指定下标(位置)的字符串:
实例
var str = "HELLO WORLD"; str.charAt(0); // 返回 H
charCodeAt() 方法
charCodeAt()
方法返回字符串中指定索引的字符 unicode 编码:
实例
var str = "Https://www.hao366.net"; str.charCodeAt(0); // 返回 72
热门文章
-
js search() 方法搜索特定值的字符串且返回匹配的位置
2023-10-09 09:01
-
js lastIndexOf() 方法返回指定文本在字符串中最后一次出现的索引
2023-10-09 09:59
-
js indexOf()查找字符串中的字符串
2023-10-09 09:58