<!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></body>
<script>
let arr = ["chen", "xiu"];
let keys = arr.keys();
console.log(keys.next()); //{value: 0, done: false}
console.log(keys.next()); //{value: 1, done: false}
console.log(keys.next()); //{value: undefined, done: true}
// 方式1
let arr1 = ["chen", "xiu"];
let values = arr1.values();
while (({ value, done } = values.next()) && done === false) {
console.log(value);
}
// 方式2
for (const value of arr1.values()) {
console.table(value);
}
// 方式3
for (const [key, value] of arr1.entries()) {
console.log(value);
}
</script>
</html>
js iterator操作数组
于 2022-02-27 20:03:22 首次发布