对数据结构读取的一种方式,有序的,连续的,基于拉取的一种消耗数据的组织方式
let arr = [1,2,3,4];
console.log(arr);
var arr1 = [1,2,3,4,5];
var ite = arr1[Symbol.iterator]();
console.log(ite);
var arr1 = [1,2,3,4];
var ite = arr1[Symbol.iterator]();
console.log(ite.next());
console.log(ite.next());
console.log(ite.next());
console.log(ite.next());
console.log(ite.next());
console.log(ite.next());
var tArr = new Int8Array(5);
tArr[0] = 100;
function myIterator(arr) {
let index = 0;
return {
next() {
return index < arr.length
? { value: arr[index++], done: false }
: { value: undefined, done: true }
}
}
}
var iter = myIterator([1,2,3,4,5]);
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
var arr = [1,2,3,4];
for (let i of arr) {
console.log(i); // 获取值
}
for (let i in arr) {
console.log(i); // 获取下标
}