1.includes 数组是否包含某个东西
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>数组includes</title>
<script>
let arr = [12, 2, 99];
alert(arr.includes(99));
</script>
</head>
<body>
</body>
</html>
2.数组
2.1 keys/values/entries
- keys=>所有的key拿出来 0,1,2,3.....
- values=>所有的values拿出来 12,5,8,99.....
- entries=>所有的key-value对拿出来 {key:0,value:12},{key:1,value:5},{key:2,value:8},{key:3,value:99}.....
2.2 for...of与for...in
操作 |
数组 |
json |
for...in |
下标(key) |
json |
for...of |
值(value) |
x |
2.3 代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>数组for-in与for-of</title>
<script>
let arr = [12, 5, 8, 99];
// 使用in,是循环出下标
// for (let i in arr) {
// alert(i);
// }
// 使用of,是循环出当前值
for (let i of arr) {
alert(i);
}
</script>
</head>
<body>
</body>
</html>