let obj = {
start: [1, 2, 3, 4, 5,],
end: [6, 7],
[Symbol.iterator]() {
let idx = 0,
arr = [...this.start, ...this.end],
len = arr.length;
return {
next() {
return idx < len ?
{
value: arr[idx++],
done:false,
}
:
{
value: undefined,
done: true,
}
}
}
}
}
for (let i in obj) {
console.log(i);
}
let arr = [1, 2, 3, 4, 5];
var iter = obj[Symbol.iterator]();
// ...拓展运算符 一定是该对象中存在Symbol.iterator属性
// 数组声明方式
// console.log(new Array()) []
// console.log(new Array(3,1)) [3,1]
// console.log(Array.of(3)); [3]
// console.log(Array.of(3,4,6)); [3,4,6]
// Array.from(likeArray,mapFn,thisArg); 可以将类数组转成数组
// [].slice.call(likeArray);
var oList = document.querySelectorAll('p');
console.log([].slice.call(oList));
console.log(Array.from(oList));
console.log(Array.from(obj));
Array.from(oList, (item, idx) => {
console.log()
console.log(item);
console.log(this.a);// undefined 箭头函数没有this
}, { a: 1 })
// fill|,copyWith,|keys,values,entries|, |includes,find,findIndex|
// fill(val,startIdx(0),endIndx(数组长度))
var arr = [1, 2, 3, 4, 5];
arr.fill(5,)