批改状态:合格
老师批语:
let str = "html".concat("css","js","php","!",888);htmlcssjsphp!8883.substr(start,size)取子串
str = "hello php.cn";let res = str.slice(0,5);console.log(res);//hellores = str.slice(6);console.log(res);//php.cn
4.trim():删除字符串两边的空白字符
res = str.substr(0,5);console.log(res);//hello
5.split() 将字符串打散成数组
let pw = " 888 ";console.log(pw.length);//11console.log(pw.trim());//888
6.replace() 替换字符串内容
res = str.split("");console.log(res);//["h", "e", "l", "l", "o", " ", "p", "h", "p", ".", "c", "n"]let email = "demo@mail.com";res = email.split("@");console.log(res);//["demo", "mail.com"]console.log('userName = ',res[0]);//userName = democonsole.log('emailAddress = ',res[1]);//emailAddress = mail.com
res = email.replace("demo","admin")console.log(res);// admin@mail.com
2.push() 在结尾处向数组添加一个新的元素
arr = ["Banana", "Orange", "Apple", "Mango"];arr.pop();console.log(arr);// ["Banana", "Orange", "Apple"]
3.shift() 删除首个数组元素
arr.push("Cherry");console.log(arr);// ["Banana", "Orange", "Apple", "Cherry"]
4.unshift() 将新元素添加到数组的开头
arr.shift();console.log(arr);// ["Orange", "Apple", "Cherry"]
arr.unshift("Lemon");console.log(arr);// ["Lemon", "Orange", "Apple", "Cherry"]
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号