1.增加
1.1 concat 拼接
var a = 'hello'
var b = "world"
console.log(a.concat(b));
2. 查询
2.1 slice(startIndex,endIndex)
2.2 substr(index,length)
注意:第二个参数 为长度
2.3 substring(startIndex,endIndex)
var arr = "hello"
console.log(arr.slice(0)); // hello
console.log(arr.slice(0,3)); // hel
console.log(arr.substr(0,3)); // hel
console.log(arr.substring(0,2)); // he
2.4 charAt(index) 根据下标查找对应的值
var str = "hello"
console.log(str.charAt(1)); // e
2.5 indexOf(value) 根据值查找对应的下标
var arr = "hello";
console.log(arr.indexOf('e')); // 1
2.6 includes 是否包含某位(多位)字符
var arr = "hello"
console.log(arr.includes("eh")); //false
3. length 字符串的长度
var str = "hello"
console.log(str.length);
var s = "故事的结尾,心上人"
console.log(handleStr(s));
function handleStr(value){
if(value.length>5){
return value.slice(0,5)+"..."
}
return value
}