<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
//length属性:获取字符串的字符个数
var msg = '你好Hello';
console.log(msg.length);
//charAt(index)方法:获取指定索引位置的字符(索引从0开始)
var msg1 = '大道无形生育天地,大道无情运行日月';
console.log(msg1.charAt(10));
//indexOf('字符串' , startIndex) 方法:获取指定字符串第一次出现的位置。startIndex表示从第几个开始搜索
var msg2 = '道家清且直';
console.log(msg2.indexOf('清'));
//split(分隔符 , limit) 根据分隔符将一个字符串返回为一个数组。limit表示要返回的数组的最大长度(可自定义)。
//var msg3 = '道德经|南华经|黄庭经|清净经|黄帝内经|心经';
//var result_msg3 = msg3.split('|', 3);
var msg3 = '道德经^南华经*黄庭经#清净经&黄帝内经|心经';
var result_msg3 = msg3.split(/\||\^|\*|\#|\&/); //使用正则表达式来拆分字符串
console.log(result_msg3);
console.log(result_msg3.length);
//substr(startIndex , len) 从startIndex开始 ,截取len个字符串
var msg4 = '跳出三界外,不在五行中。六道绝踪迹,十方无影像';
msg4 = msg4.substr(6,5);
console.log(msg4);
//substring(startIndex , stopIndex) 从startIndex开始 , 截取到stopIndex位置
var msg5 = '跳出三界外, 不在五行中。六道绝踪迹 , 十方无影像';
msg5 = msg5.substring(13 , 18);
console.log(msg5);
//toUpperCase() 转换大写 , toLowerCase(); 转换小写
var msg6 = 'AaBbCcDdEe';
console.log(msg6.toUpperCase());
console.log(msg6.toLowerCase());
//Date 和 Math 对象
var date = new Date();
console.log(date.getDate());
console.log(date.getFullYear());
console.log(date.getMonth()); //返回当前月份的索引值
console.log(date.getDay()); //返回当前一周的第几天
console.log(date.getHours());
console.log(date.getMinutes());
console.log(date.getSeconds());
console.log(Math.abs(-9));
console.log(Math.random());
</script>
</head>
<body>
</body>
</html>