查找
- indexOf()
- lastIndexOf()
- startsWith()
- 是否以什么开头
- endsWith()
- 是否以什么结尾
- includes() ```javascript let stringValue = “hello world”; console.log(stringValue.indexOf(“wo”)); // 6 console.log(stringValue.lastIndexOf(“o”)); // 7
let message = “foobarbaz”; console.log(message.startsWith(“foo”)); // true console.log(message.startsWith(“bar”)); // false
console.log(message.endsWith(“baz”)); // true console.log(message.endsWith(“bar”)); // false
console.log(message.includes(“bar”)); // true console.log(message.includes(“qux”)); // false
<a name="EYnh3"></a>#### 字符串的截取> 都是不改变原来字符串,返回新字符串> 后往前截取使用负值- slice()- 参数- 参数1: 开始位置- 参数2: 结束位置(不包含)- substr()- 无论中文、英文,都是一位一截- 参数- 参数1:开始位置- 参数2:截取长度- substring()- 参数- 参数1:开始位置- 参数2:结束位置(不包含)<a name="vao80"></a>#### 删除空白符> 空白符包括空格、制表符、换行符```javascriptvar str = " Runoob ";console.log(str.trim()) // Runoob
字母大小写转换
- toLowerCase()
- 字符串都转换为小写
- toUpperCase()
- 字符串都转换为大写
let stringValue = "hello world";console.log(stringValue.toLocaleUpperCase()); // "HELLO WORLD"console.log(stringValue.toUpperCase()); // "HELLO WORLD"console.log(stringValue.toLocaleLowerCase()); // "hello world"console.log(stringValue.toLowerCase()); // "hello world"
String转Number
let s = '5'let n = +s; // 字符串转数字
- 字符串都转换为大写
