标签:截取 arc 出现 pre gpe 大写转小写 str1 div unicode
var t = "true"; console.log(typeof t);// "string" console.log(typeof true);// "boolean" var str = "yyy./NIha"; var s = ‘www‘; var str = "helloworld";
console.log(str[3]);// "f";
console.log(str.length); //获取一个字符串最后一个字符; console.log(str[str.length - 1]);
console.log("6" - 2);// 4 console.log("5"/"4")// 1.25 console.log("5px"-"4")// NaN console.log(true*"4")// 4
任何数字和NaN 计算,结果都是NaN; 任何数字和undefined运算,得到也是NaN;
console.log("6px"+undefined); console.log(NaN+"undefined"); [] : 空数组在进行拼接时,会默认调用toString转换成空字符串;然后拼接; var a = typeof 10 + true + [] + null + undefined+{}; // "numbertruenullundefined" console.log(a);
str.toUpperCase()var str1 = “HELLO”
console.log(str1.toLowerCase());
console.log(str.charAt(4));
a-z : 97–122 0-9 : 48-57 A-Z : 65-90console.log(str.charCodeAt(0));
substr(m) : 从索引m开始截取到末尾console.log(str.substr(2));console.log(str.substr(2,5));
当n是负数时,m截取到开头; 不支持负数;console.log(str.substring(2, 5));console.log(str.substring(5, -1));
支持负数的的截取;console.log(str.slice(3, 7));console.log(str.slice(3, -1));console.log(str.slice(3, 0));
返回索引;如果字符串不存在,返回-1;console.log(str.indexOf(“e”));// 4console.log(str.indexOf(“w”));// -1
返回索引;如果字符串不存在,返回-1;console.log(str.lastIndexOf(“n”));console.log(str.lastIndexOf(“k”));
console.log(str.split(“”));var str = “zhufengpeixun”;
console.log(str.replace(“u”, “m”).replace(“u”, “m”));字符串.replace(oldStr,newStr);console.log(str);var str1 = “hellohello”;console.log(str1.replace(“hello”, “helloworld”).replace(“hello”, “helloworld”));//”helloworldworldhello”
var str = “aer”;console.log(str.concat(“123”));// “aer123”
trimLeft : 去字符串左边的空格trimRight : 去字符串右边的空格;var str = ” 66yy yww “;str.trim()
标签:截取 arc 出现 pre gpe 大写转小写 str1 div unicode
原文地址:https://www.cnblogs.com/CCxi/p/9448194.html