concat 连接两个字符串indexOf 可以查询字符串中某个字符的下标slice(startIndex,endIndex) 截取字符串的某一段includes() 可以判断字符串中是否有该字符/字符串substr(index,length) 截取字符串 第一个参数:开始下标,第二个参数:截取长度substring(statIndex,endIndex) 截取字符串 第一个参数:开始下标,第二个参数:结束下标,不包含结束 下标charAt 通过指定下标,获取字符串中的字符search 通过value值找到其在字符串中的下标,如果返回为-1,就是没找到 indexOfincludessearch match这四个方法都是用来判断字符串或数组是否有该值match返回的是一个数组,将匹配的字符返回为一个数组,存在返回一个数组,不存在返回一个nullreplace(参数1,参数2)替换/替代 第一个参数:旧值,第二个参数:新值split 将字符串分割成数组
var str = 'hello' var b = 'world' // concat var res = str.concat(b) console.log(res); //helloworld // indexOf console.log(str.indexOf("l")); //2 //slice console.log(str.slice(1,4)); //ell // includes console.log(str.includes("e")); //true // substr console.log(str.substr(1,3)); // sbustring var list = str.substring(1,4) console.log(list); //ell // charAt console.log(str.charAt(1)); console.log(str[1]); // search console.log(str.search("o"));//4 console.log(str.search("p"));//-1 // match var test = "你好你来你的" var result = test.match("你") console.log(result); //['你', index: 0, input: '你好你来你的', groups: undefined] console.log(result.length); //1 console.log(str.match("他")); //null console.log(null == true); //false null做布尔判断运算,返回结果都为false // replace console.log(str.replace("h","他")); var s = 'hrllo' console.log(s.replace("l","*")); // split console.log(str.split()); //["hello"] console.log(str.split("")); //['h', 'e', 'l', 'l', 'o'] console.log(str.split("e")); //['h', 'llo']