String
全局对象是一个用于字符串或一个字符序列的构造函数
返回特定位置的字符。
var s = "abcdefg";
var c = s.charAt(1);
console.log(c); // b
返回字符串长度。
var s = "abcdefg";
var c = s.length;
console.log(c); // 7
连接两个字符串文本,并返回一个新的字符串
var s1 = "abc ";
var s2 = "def";
var c = s1.concat(s2, "**");
console.log(c); // abc def**
从字符串对象中返回首个被发现的给定值的索引值,如果没有找到则返回-1。
var s = "abcdef";
var c = s.indexOf("c", 3);
console.log(c); // -1
检索返回一个字符串匹配正则表达式的的结果
var s = "hello<h3>world</h3>";
var reg = /<\w+>\w+<\/\w+>/;
var res = s.match(reg);
构造并返回一个新字符串,该字符串包含被连接在一起的指定数量的字符串的副本
"abc".repeat(2); // "abcabc"
提取某个字符串的一部分,并返回一个新的字符串
var s = "abcdefgh";
var res = s.slice(2, 5);
console.log(res); //cde
使用指定的分隔符字符串将一个 String 对象分割成子字符串数组
var s = "hell,af,er,t,t";
var res = s.split(",");
console.log(res); // ["hell", "af", "er", "t", "t"]
从一个字符串的两端删除空白字符
var greeting = " Hello world! ";
console.log(greeting.trim());
判断当前字符串是否以另外一个给定的子字符串结尾
let s = "hello world";
// 后面的数字代表取前几位字符串作为比对
console.log(s.endsWith("lo", 5)); // true
判断当前字符串是否以另外一个给定的子字符串开头
let s = "hello world";
// 后面的数字代表从下标第几位开始匹配
console.log(s.startsWith("el", 1)); // true