与字符串相关
var str="hello world";
str.slice(4,7); //o w 起始位置和结束位置(不包括结束位置)
str.substring(4,7); //o w 起始位置和结束位置(不包括结束位置)
str.substring(7,4); //o w 较小的为起始位置,较大的为结束位置
str.substr(4,7); //o world 起始位置和所要返回的字符串长度
str.search('ll'); //2 检索字符串中指定的子字符串,或检索与正则表达式相匹配的子字符串
//--------------------------------------------
str.slice(-3); //rld 将它字符串的长度与对应的负数相加,结果作为参数
str.slice(3,-4); //lo w 将它字符串的长度与对应的负数相加,结果作为参数
str.substring(-3); //hello world 将负参数都直接转换为0
str.substring(3,-4); //hel 将负参数都直接转换为0
str.substr(-3); //rld 将第一个参数与字符串长度相加后的结果作为第一个参数
str.substr(3,-4); //空字符串 将第一个参数与字符串长度相加后的结果作为第一个参数
//-----------------------------------------------------------------
str.indexOf("e"); //1 第一个匹配的字符串索引位置
str.replace("o","!"); //只会替换第一个匹配的o字符串替换为!
str.replace(/o/g,"!"); //替换所有匹配的o字符串替换为!
str.charAt(2); //l 指定索引位置2处的字符
var str2=str.toUpperCase(); //HELL0 WORLD 变成大写字符串
str2.toLowerCase(); //hello world 变成小写字符串
'中文 zh-CN'.toLocaleLowerCase(); // '中文简体 zh-cn' 根据任何特定于语言环境,将调用字符串的字
// 符串转换为小写
'中文 zh-CN'.toLocaleUpperCase(); // '中文 ZH-CN' 根据任何特定于语言环境,将调用字符串的字
// 符串转换为大写
str.includes('or'); //true 当前字符串包含被搜寻的字符串 第二参可选,开始索引
str.padStart(5); // 'hello world'字符串开头填充指定的填充字符串到目标长度的新字符串。
//参数1 当前字符串需要填充到的目标长度。如果这个数值小于当前
//字符串的长度,则返回当前字符串本身。 参数2 填充字符串。如果字符串太长,使填充后的字符串
//长度超过了目标长度,则只保留最左侧的部分,其他部分会被截断。此参数的缺省值为 " "
str.padEnd(13,'0'); //'hello world00'
String.fromCharCode(666,65); // 'aA' 使用指定的Unicode值(666,65)序列创建的字符串
"ABC".charCodeAt(1) // 66 是一表示给定索引处(String中index索引处)字符的UTF-16 代码单元值的数字
//如果索引超出范围,则返回 NaN
'hello'.concat(' world', '!'); // 'hello world!' 将一个或多个字符串与原字符串连接合并,形成一个
//新的字符串并返回。
str.endsWith('world', 10); // false 判断当前字符串是否是以另外一个给定的子字符串“结尾”的,
//10为截取字符串str的长度,从前面截取
str.lastIndexOf("o", 6); // 4 指定值在调用该方法的字符串中最后出现的位置,从该字符串的后面向前
//查找,从 fromIndex(参数 6) 处开始
var str3 = 'For more information, see Chapter 3.4.5.1';
var re = /see (chapter \d+(\.\d)*)/i;
var found = str3.match(re);
console.log(found);
// [ 'see Chapter 3.4.5.1',
// 'Chapter 3.4.5.1',
// '.1',
// index: 22,
// input: 'For more information, see Chapter 3.4.5.1' ]
// 'see Chapter 3.4.5.1' 是整个匹配。
// 'Chapter 3.4.5.1' 被'(chapter \d+(\.\d)*)'捕获。
// '.1' 是被'(\.\d)'捕获的最后一个值。
// 'index' 属性(22) 是整个匹配从零开始的索引。
// 'input' 属性是被解析的原始字符串。
'ABCDabcd'.match(/[A-B]/gi); // ["A", "B", "a", "b"]
"abc".repeat(0) // "" 包含指定字符串的指定数量副本的新字符串。
"abc".repeat(1.5) // "abc"
'ABCDabcd'.search(/[A-B]/gi); // 0 返回正则表达式在字符串中首次匹配项的索引。否则,返回 -1
'1-2-3-4-5'.split("-"); // ["1", "2", "3", "4", "5"] 返回源字符串以分隔符出现位置分
//隔而成的一个 Array
'ABCDabcd'.startsWith('CD', 2); //true 判断当前字符串是否是以另外一个给定的子字符串“开头”的
var x = new String("Hello world"); // String {"Hello world"}
typeof(x) // 'object'
x.toString(); // 'Hello world' 返回指定对象的字符串形式
x.valueOf(); // 'Hello world' 返回一个String对象的原始值
' foo '.trim(); //'foo' 从一个字符串的两端删除空白字符