| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- var str = 'Happy New Year';
- console.log(str,'原本的')
- //toUpperCase 将字符串中所有字符转成大写
- console.log(str.toUpperCase());
- //toLowerCase 将字符串中所有字符转成小写
- console.log(str.toLowerCase());
- var str2 = 'hi';
- // concat 将字符串连接在一起
- var str1 = str.concat(str2);
- console.log(str1);
- var str3 = ' hello , w orld ';
- console.log(str3);
- // 4.trim 取消字符串前后空格
- console.log(str3.trim())
- var str4 = 'This is a cup is';
- // indexOf 查找字符首次出现的下标索引位置
- // console.log(str4.indexOf("is"));
- // // lastIndexOf 查找字符最后出现的下标索引位置
- // console.log(str4.lastIndexOf("is"));
- // 截取 slice
- // 一个值:从哪个下标开始截取到最后,负数从-1开始
- // 两个值: 第一个值开始截取的下标索引 第二个结束的下标索引 但不包含该索引
- // console.log(str4.slice(-5,-2))
- // 截取 substr
- // 一个值:从哪个下标开始截取到最后,负数从-1开始
- // 两个值: 第一个值开始截取的下标索引 第二个代表截取的长度
- // 截取 substring
- // 一个值:从哪个下标开始截取到最后
- // 两个值: 第一个值开始截取的下标索引 第二个结束的下标索引 但不包含该索引
- // console.log(str4.substr(3))
- // console.log(str4.substring(5,9))
- var str5 = 'hi~hello~hi';
- // replace 替换
- // console.log(str5.replace("hi",'图图'));
- // console.log()
- // split 字符串转数组
- // console.log(str5.split("~"))
- // charAt 查找当前下标的字符
- console.log(str5.charAt(7))
- </script>
- </body>
- </html>
|