console.log(new Array());
console.log(new Array(3));
console.log(new Array(3, 1));
console.log(Array.of());
console.log(Array.of(1));
console.log(Array.of(1, 2));
var obj = {
start: [12,3,4,5],
end: [7,8,9],
[Symbol.iterator](){
let index = 0,
arr = [...this.start,...this.end],
len = arr.length;
return {
next(){
if(index<len){
return {
value: arr[index++],
done: false
}
}else{
return {
value: undefined,
done: true
}
}
}
}
}
}
console.log(Array.from(obj))
var obj = {
start: [12,3,4,5],
end: [7,8,9],
[Symbol.iterator](){
let index = 0,
arr = [...this.start,...this.end],
len = arr.length;
return {
next(){
if(index<len){
return {
value: arr[index++],
done: false
}
}else{
return {
value: undefined,
done: true
}
}
}
}
}
}
console.log(Array.from(obj, function mapper(val, index){
return val * 2;
}))
arr.fill(value, start, end) 填充, 修改原数组(左闭右开区间)
var arr = [1,2,3,4];
arr.fill(5);
console.log(arr); // [5, 5, 5, 5]
var arr = [1,2,3,4];
arr.fill(5, 1);
console.log(arr); // [1, 5, 5, 5]
var arr = [1,2,3,4];
arr.fill(5, 1, 3);
console.log(arr); // [1, 5, 5, 4]
var arr = [1,2,3,4];
arr.fill(5, -3, -2);
console.log(arr); // [1, 5, 3, 4]
var arr = [1,2,3,4];
arr.fill(5, NaN, -2); // NaN 被当成0处理
console.log(arr); // [5, 5, 3, 4]
var arr = [1,2,3,4];
arr.fill(5, NaN, NaN); // 不做处理
console.log(arr); // [1, 2, 3, 4]