详解length charAt indexOf lastIndexOf includes concat slice substring substr详解

<!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 type="text/javascript">
		/*
        在js中字符串可以看做一个特殊的数组, 所以大部分数组的属性/方法字符串都可以使用
        */
       // 1.获取字符串长度  .length
       let a="abcd";
       //console.log(a.length);
       // 2.获取某个字符 [索引] / charAt
       let b="abcd";
       let c=b.charAt(1);
       //console.log(c);
        // 3.字符串查找 indexOf / lastIndexOf / includes
        let aa="abcde";
        let ss=aa.indexOf("c");
        //console.log(ss);
           let sss=aa.lastIndexOf("e");//从后往前数第一个e
           console.log(sss);
           let ddd=aa.includes("ss");
 console.log(ddd);

        // 4.拼接字符串 concat / +
        let str1 = "www";
         let str2 = "it666";
         let x=str2+str1;
         console.log(x);
         let v=str1.concat(str2);
         console.log(v);
         // 5.截取子串 slice / substring / substr
           let str = "abcdef";
           let m=str.slice(1,3);//从下标1开始截取两位。
           console.log(m);
            let subStr = str.substring(1, 3);
            console.log(subStr);
            let f=str.substr(1,3);//从下标1开始截取三位.
            console.log(f);
	</script>
</body>
</html>

你可能感兴趣的:(详解length charAt indexOf lastIndexOf includes concat slice substring substr详解)