<!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> // let name ="a" // let email = name; // console.log(email); console.log(String.prototype); // 1.concat():字符串拼装学习 // 方法一:加号拼接字符串 let str = "html" + ", css" + ", js"; console.log(str); // 方法二:函数拼接字符串:便于集合化处理 str = "html".concat(", css", ", js"); console.log(str); // 2.slice(start开始 , end结束):从子串 str = "hello php.cn"; // h-0 // e-1 // l-2 // l-3 // 0-4 // 空格-5 结果中不包括结束索引的字符 let res = str.slice(0,5); console.log(res); res = str.slice(0); console.log(res); res = str.slice(5); console.log(res); res = str.slice(-1); console.log(res); res = str.slice(-2); console.log(res); res = str.slice(-3); console.log(res); // 2.1取子串 res = str.substr (0,5); console.log(res); res = str.substr(-6,3); console.log(res); res = str.substr(-10,2); console.log(res); // 3.trim();删除两边的二空白字符 let psw1 = "admin123"; let input = "admin123"; console.log(psw1 === input); psw1 = "admin123"; input = " admin123 "; console.log(psw1 === input); psw1 = "admin123"; input = " admin123 "; console.log(input.length); input = input.trim(); console.log(input); console.log(psw1 === input); // 字符转数组 res = str.split(""); console.log(res); res = str.split(" "); console.log(res); console.log("" === " "); console.log("html-css-js".split("-")); let email = "[email protected]"; res = email.split("@"); console.log(res); console.log("账号:%s",res[0]); </script> </body> </html>
<!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> // 1.push尾部添加 let arr = []; arr.push(4); console.log(arr); console.log(arr.push("a")); console.log(arr); console.log(arr.push("b","c","d")); console.log(arr); // 2.pop尾部删除 console.log(arr.pop()); console.log(arr); console.log(arr.pop()); console.log(arr); // 3.unshift();头部添加 console.log(arr.unshift(1,2,3)); console.log(arr); // 4.shift()头部删除 console.log(arr.shift()); console.log(arr.shift()); console.log(arr.shift()); console.log(arr); </script> </body> </html>
标签:常用,console,log,res,arr,str,数组,字符串,input From: https://www.cnblogs.com/QWD7986/p/18238772