操作字符串的方法~
- concat(“连接的字符串”)连接字符串
var a = "hello";
var b = a.concat("word");
console.log(b);
- indexOf()查询某个字符串在原字符串中首次出现的位置(下标)
var a = "hello word";
var b = a.indexOf("o");
如果查询不到值是否存在返回-1
3. charAt(下标)查找下标所在位置对应的字符
var a = "hello word";
var b = a.charAt(4);
console.log(b);
- lastIndexOf(查询的字符)
var a = "hello word";
var b = a.lastIndexOf("o");
var b = a.lastIndexOf("a");
console.log(b);
操作字符串的方法~
- concat(“连接的字符串”)连接字符串
var a = "hello";
var b = a.concat("word");
console.log(b);
- indexOf()查询某个字符串在原字符串中首次出现的位置(下标)
var a = "hello word";
var b = a.indexOf("o");
如果查询不到值是否存在返回-1
3. charAt(下标)查找下标所在位置对应的字符
var a = "hello word";
var b = a.charAt(4);
console.log(b);
- lastIndexOf(查询的字符)
var a = "hello word";
var b = a.lastIndexOf("o");
var b = a.lastIndexOf("a");
console.log(b);
操作字符串的方法~
- concat(“连接的字符串”)连接字符串
var a = "hello";
var b = a.concat("word");
console.log(b);
- indexOf()查询某个字符串在原字符串中首次出现的位置(下标)
var a = "hello word";
var b = a.indexOf("o");
如果查询不到值是否存在返回-1
3. charAt(下标)查找下标所在位置对应的字符
var a = "hello word";
var b = a.charAt(4);
console.log(b);
- lastIndexOf(查询的字符)
var a = "hello word";
var b = a.lastIndexOf("o");
var b = a.lastIndexOf("a");
console.log(b);
操作字符串的方法~
- concat(“连接的字符串”)连接字符串
var a = "hello";
var b = a.concat("word");
console.log(b);
- indexOf()查询某个字符串在原字符串中首次出现的位置(下标)
var a = "hello word";
var b = a.indexOf("o");
如果查询不到值是否存在返回-1
3. charAt(下标)查找下标所在位置对应的字符
var a = "hello word";
var b = a.charAt(4);
console.log(b);
- lastIndexOf(查询的字符)
var a = "hello word";
var b = a.lastIndexOf("o");
var b = a.lastIndexOf("a");
console.log(b);
查询最后字符的下标查询不到返回
- unshift()添加,增加在原数组最开始
var arr = [11,22,33,44,55];
var b = arr.unshift(66);
console.log(b);
console.log(arr);
在数组的开头增加元素,并将数组的长度增加
- charCodeAt(下标)输出ascll码(键盘2进制值) …使用较少
var a = "Ehello word";
var b = a.charCodeAt(2);
var c = a.charCodeAt(0);
console.log(b);
console.log(c);
- isNaN(检测字符串是否为数字字符串)
var a = "abc";
var b = isNaN(a);
console.log(b);
console.log(isNaN("abc"));
console.log(isNaN("123"));
- trim()清除字符串前后空格
var a = " abc ";
var b = a.trim();
a = a.trim();
console.log(b);
console.log(a);
- split()切割字符串,会变成数组
var a = "hello word";
var b = a.split("o");
console.log(b);
```1. ***toUpperCase()转大写==toLocaleUpperCase()***
```javascript
var a = "abcdefg";
console.log(a.toUpperCase());
- toLowerCase()转小写==toLocaleLowerCase()
var b = "ABCDEFG";
console.log(b.toLowerCase());
7. ***isNaN(检测字符串是否为数字字符串)***
```javascript
var a = "abc";
var b = isNaN(a);
console.log(b);
console.log(isNaN("abc"));
console.log(isNaN("123"));
- trim()清除字符串前后空格
var a = " abc ";
var b = a.trim();
a = a.trim();
console.log(b);
console.log(a);
- split()切割字符串,会变成数组
var a = "hello word";
var b = a.split("o");
console.log(b);
```1. ***toUpperCase()转大写==toLocaleUpperCase()***
```javascript
var a = "abcdefg";
console.log(a.toUpperCase());
- toLowerCase()转小写==toLocaleLowerCase()
var b = "ABCDEFG";
console.log(b.toLowerCase());