Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
<!DOCTYPE html>
<html lang="zh-CN">
<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>字符串api和数组api实例演示</title>
</head>
<body>
<script>
let xu = "许可可博客";
//获取字符串长度
console.log(xu.length);
//按照索引方式获取字符元素'可'
console.log(xu[2]);
//按照元素方式获取索引值
console.log(xu.indexOf("可"));
//从某个位置开始取几个字符 支持负数 也就是从后往前取
console.log(xu.substr(1, 3)); //从索引[1]开始取3个
// 字符串替换 必须要相邻的字符 前面是被替换的后面是替换后的
console.log(xu.replace("许可", "xukeke"));
//数组
//数组的两种遍历方式
let arr = [1, 2, 3, 4, 5, 6, 7, 8];
console.log(arr.length);
// forEach方法
let res = arr.forEach((itme, index, arr) =>
console.log(itme, index, arr)
);
console.log(res);
// map方法
res2 = arr.map((itme) => itme * 5);
console.log(res2);
//every:全部满足条件就返回ture
console.log(arr.every((itme) => itme >= 0));
console.log(arr.every((itme) => itme >= 2));
// some:只有有一个满足条件就返回ture
console.log(arr.some((itme) => itme >= 7));
console.log(arr.some((itme) => itme >= 2));
//返回符合条件的第一个元素 find
console.log(arr.find((itme) => itme >= 9));
console.log(arr.find((itme) => itme >= 8));
</script>
</body>
</html>