增加
1.1 concat 拼接
var a = 'hello'var b = "world"console.log(a.concat(b));
查询
1.2 str[i]
var str="hello"console.log(str[0]);//h
1.3 indexOf(value) 根据值查找对应的下标
var str="hello"console.log(str.indexOf("o")) //输出某个字符对应的下标值
1.4 slice(startIndex,endIndex)
var arr = "hello"console.log(arr.slice(0)); // hello 截取从某个下标开始console.log(arr.slice(0,3)); // hel
1.5 includes 是否包含某位(多位)字符
var arr = "hello"console.log(arr.includes("eh")); //false
1.6 substring (startIndex,endIndex)
var str="hello"console.log(str.substring(0,3))
1.7 substr(index,length) 截取从某个下标开始的之后的某个长度
var str="hello"console.log(str.substr(0,2)) // he
1.8 charAt(index) 根据下标查找对应的值
var str="hello"console.log(str.charAt(1)) //输出某一个下标值的字符
1.9 search 根据值查找对应的下标 找不到返回-1
var str = "helloworld";var res = str.search("r");console.log(res)console.log(str.search("a"))
1.10 match 返回匹配的字符串
/* match返回的是一个数组,将匹配的字符返回一个数组 */ /* 1、存在 数组 2、不存在 null */ var str ="你好你来你的"; var res = str.match("你"); /* ["你"] */ console.log(res) console.log(str.match("他"))
其它
1.11 replace()替换字符串
var str = "hello"console.log(str.replace("l","*")); // he*lo
1.12 split()将字符串分割成字符串数组
var str = "hello"console.log(str.split()); // 将字符串转为数组 ["hello"]console.log(str.split("")); // ["h","e","l","l","o"]console.log(str.split("e"));// ["h","llo"]
1.13 trim( ) 去除字符串前后的空格
// 正则表达式: /^\s+|\s+$/g var str = " hello ";var arr = []arr.push(str.trim())console.log(arr)
1.14 startsWith( ) 以…开头的字符串
// startsWith() 以...开头的字符串// endsWith()var str = "武汉"console.log(str.startsWith("武")) // trueconsole.log(str.endsWith("汉"))