字符串
字符串字面表达
\'foo\'
\"bar\"
Hexadecimal转义序列
\'\\xA9\' // \"©\"
Unicode转义序列
\'\\u00A9\' // \"©\"
Unicode code point escape
\'\\u{2F804}\'
// the same with simple Unicode escapes
\'\\uD87E\\uDC04\'
字符串对象
字符串对象是对原始字符串数据类型的封装
const foo = new String(\'foo\'); // Creates a String
console.log(foo); // Displays: [String: \'foo\']
typeof foo; // Returns \' \'
const firstString = \'2 + 2\'; // Creates a string literal value
const secondString = new String(\'2 + 2\'); // Creates a String
eval(firstString); // Returns the number 4
eval(secondString); // Returns the string \"2 + 2\"
const hello = \'Hello, World!\';
const helloLength = hello.length;
hello[0] = \'L\'; // This has no effect, because strings are immutable
hello[0]; // This returns \"H\"
字符串对象的方法
| charAt, charCodeAt, codePointAt | 返回索引指定位置的字符或者字符编码 |
| indexOf, lastIndexOf | 返回指定子字符串初次出现的位置,或者最后一次出现的位置 |
| startsWith, endsWith, includes | 判断是否以某指定文字起始、结尾、或者包含某指定文字 |
| concat | 连接两个字符串,以新字符串返回 |
| fromCharCode, fromCodePoint | 基于Unicode值创建字符串 |
| split | 依据指定的分割符,将字符串分割写入数组 |
| slice | 将字符串切割为片段,返回新字符串 |
| subString, subStr | 依据指定索引返回子字符串 |
| match, replace, search | 同正则表达式一起工作 |
| toLowerCase, toUpperCase | 大小写转换 |
| normalize | 返回字符串的Unicode Normalization Form |
| repeat | 取得该字符串指定重复次数的字符串 |
| trim | 除去字符串起始和结尾的空白 |
继续阅读与本文标签相同的文章
上一篇 :
直播卖货很火,你被从众心理利用过吗?
下一篇 :
【Linux函数】Signal ()函数
-
猫和老鼠:5种药水效果可以叠加吗?这2种药水效果会有冲突!
2026-05-18栏目: 教程
-
自媒体教程,深度剖析平台的推荐机制原理,了解怎么获取高流量
2026-05-18栏目: 教程
-
宽带故障怎么办?教你几招,轻松解决!
2026-05-18栏目: 教程
-
Python 3.8刚刚发布!一分钟了解新版本的强大功能!
2026-05-18栏目: 教程
-
《中国工夫》聚焦“中国智造”
2026-05-18栏目: 教程
