1.字符串的声明和方法
声明字符串的三种方法
-
用单引号声明
-
/用双引号声明
-
用反引号声明
2.字符串和数组之间的相互转换
1.字符串转化为数组 split
1.数组转化为字符串 join
3.多行字符串
方法:
1.字符串相加
2.使用反斜杠
3.模板字符串
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 声明字符串
let str1 ='江软学子牛逼';
let str2 ='江软学子牛逼';
let str3 ='江软学子牛逼';
// 判断一个字符串在不在某个字符串里面
let index1 =str1.indexOf('江软');
console.log(index1);
let str4 = str1.substr(2,3)
console.log(str4);
let str5 = str1.replace('江软','二班')
console.log(str5);
console.log('ABCD'.toLowerCase());
console.log('abcd'.toUpperCase());
console.log('中文不存在大小写'.toLowerCase);
//小练习
let str = '星期天,星期一,星期二,星期三,星期四,星期五,星期六';
let today = new Date();
console.log(today);
let day = today.getDay();
console.log(day);//3
let arr = str.split(',')
console.log(arr);
console.log("今天是;"+arr[day]);
let str11 = "I am "+
"dangerous";
console.log(str11);
let str22 ="I am\
dangerous";
console.log(str22);
let str33=
`I
am
dangerous`;
console.log(str33);
//定义变量
let name=`艺术`;
let skill =`爆炸`;
//字符串中嵌入变量
document.write(`${name}就是${skill}`)
</script>
</body>
</html>
效果图如下: