1-1 增加

1-1-1 concat 拼接

  1. var a = 'hello'
  2. var b = "world"
  3. console.log(a.concat(b));

1-2 查询

1-2-1 slice(startIndex,endIndex)

1-2-2 substr(index,length)

注意:第二个参数 为长度

1-2-3 substring(startIndex,endIndex)

  1. var arr = "hello"
  2. console.log(arr.slice(0)); // hello
  3. console.log(arr.slice(0,3)); // hel
  4. console.log(arr.substr(0,3)); // hel
  5. console.log(arr.substring(0,2)); // he

1-2-4 charAt(index) 根据下标查找对应的值

  1. var str = "hello"
  2. console.log(str.charAt(1)); // e

1-2-5 indexOf(value) 根据值查找对应的下标

  1. var arr = "hello";
  2. console.log(arr.indexOf('e')); // 1

1-2-6 includes 是否包含某位(多位)字符

  1. var arr = "hello"
  2. console.log(arr.includes("eh")); //false

1-2-7 search(index)

  1. var str="你是谁";
  2. var index=str.search("是");
  3. console.log(index);

1-2-8 match 匹配

  1. var str="hello";
  2. var arr=str.match("l");
  3. console.log(arr);

1-3 length 字符串的长度

  1. var str = "hello"
  2. console.log(str.length);
  3. var s = "故事的结尾,心上人"
  4. console.log(handleStr(s));
  5. function handleStr(value){
  6. if(value.length>5){
  7. return value.slice(0,5)+"..."
  8. }
  9. return value
  10. }

1-4 trim()去除字符串前后的空格

  1. var str=" hello ";
  2. var arr=[];
  3. arr.push(str.trim());
  4. console.log(arr);

1-5 replace()替换字符串中的元素

  1. var str="hello";
  2. console.log(str.replace("l","*"))

1-6 split()将字符串转换为数组

  1. var str="hello";
  2. var arr=str.split("");//["h", "e", "l", "l", "o"]

1-7 判断开始结束 返回boolean

  1. var str="武汉";
  2. console.log(str.startsWith("武"));
  3. console.log(str.endsWith("汉"))