1. concat()拼装
    let str = "html".concat("css","js","php","!",888);
    htmlcssjsphp!888
  2. slice(start,end)取子串
    1. str = "hello php.cn";
    2. let res = str.slice(0,5);
    3. console.log(res);//hello
    4. res = str.slice(6);
    5. console.log(res);//php.cn
    3.substr(start,size)取子串
    1. res = str.substr(0,5);
    2. console.log(res);//hello
    4.trim():删除字符串两边的空白字符
    1. let pw = " 888 ";
    2. console.log(pw.length);//11
    3. console.log(pw.trim());//888
    5.split() 将字符串打散成数组
    1. res = str.split("");
    2. console.log(res);//["h", "e", "l", "l", "o", " ", "p", "h", "p", ".", "c", "n"]
    3. let email = "demo@mail.com";
    4. res = email.split("@");
    5. console.log(res);//["demo", "mail.com"]
    6. console.log('userName = ',res[0]);//userName = demo
    7. console.log('emailAddress = ',res[1]);//emailAddress = mail.com
    6.replace() 替换字符串内容
    1. res = email.replace("demo","admin")
    2. console.log(res);// admin@mail.com

    数组方法

    1.pop() 从数组中删除最后一个元素
    1. arr = ["Banana", "Orange", "Apple", "Mango"];
    2. arr.pop();
    3. console.log(arr);// ["Banana", "Orange", "Apple"]
    2.push() 在结尾处向数组添加一个新的元素
    1. arr.push("Cherry");
    2. console.log(arr);// ["Banana", "Orange", "Apple", "Cherry"]
    3.shift() 删除首个数组元素
    1. arr.shift();
    2. console.log(arr);// ["Orange", "Apple", "Cherry"]
    4.unshift() 将新元素添加到数组的开头
    1. arr.unshift("Lemon");
    2. console.log(arr);// ["Lemon", "Orange", "Apple", "Cherry"]

更多相关文章

  1. js基础知识:字符串数组方法及留言本实例
  2. 从键盘输入若干个学生成绩,输入负数作为输入结束标记,用数组和函数
  3. 留言板添加字数实时统计和超出判断以及数组字符串方法
  4. js判断一个字符串是否是数字
  5. 购物车功能:全选与取消,自动计算----0412
  6. 0415作业-Vue常用指令及方法
  7. 为留言板添加字数实时统计与禁止超出功能; 2. 自选一些字符串和
  8. 留言板,字符串和数组方法 ----0407
  9. 【DB笔试面试462】如何将一个数字转换为字符串并且按照指定格式

随机推荐

  1. c语言puts函数用法是什么?
  2. C语言函数基础知识有哪些?
  3. c语言中==是什么意思?
  4. 适合小白入门C语言的简单教程
  5. 数组指针的用法有哪些?
  6. c语言中include用法是什么?
  7. visual c++6.0怎么新建C语言项目
  8. c语言字符数组与字符串应用方法是什么?
  9. c语言fgets函数用法是什么?
  10. C语言中continue的作用是什么