画布 1
Array
  增 删
    unshift(item)：把item追加到开头
    push(item)：把item追加到尾部
    shift()：删除第一个元素
    pop()：删除最后一个元素
    delete xxx：只删除value而不改变索引，会导致稀疏数组和内存泄漏
    length = 0：直接删除整个数组
    他们的返回值是被追加或被取出的元素，都为破坏性。或许更适合操作stack栈。
    推荐使用splice来进行删除的操作
  转换
    join：数组添加间隔转换为字符串
      split：字符串根据某值分割为数组
    flat：扁平化，将多维数组降维
  遍历
    forEach：传入（item, index, array)=>xxx 无返回值
    map：传入（item, index, array)=>xxx 返回值是操作后的新数组
    reduce：传入（accumulator, item, index, array)=>xxx 返回值是累计值（逆序可以使用reduceRight）
    some：测试数组中是否至少有一个元素通过了由提供的函数实现的测试，返回布尔值。
    every：测试一个数组内的所有元素是否都能通过指定函数的测试，返回布尔值。
    find：返回数组中满足提供的测试函数的第一个元素的值。
    filter：返回通过所提供函数实现的测试的所有元素组成的新数组。
    for...of：取出每一项元素
  拼接
    concat：向原数组拼接新数组或新元素
    [,,,a, ...b]：展开数组来拼接出一个新数组
  改
    splice：（开始索引，删除个数，添加内容）
      删除：splice(2，3)：从2处开始删除3个
      增加：splice(1，0，‘abc’)：1处后面追加一个‘abc’
      替换：splice(3，1，‘p’)：将3处的元素替换为‘p'
    reverse(arr)：对数组顺序进行反转，返回这个数组
    sort：依据传入的函数对数组进行排序
    破坏性，如果不想改变原数组，请使用toSpliced, toReversed, toSorted
  查
    includes(value)：判断一个数组是否包含一个指定的值，返回布尔值。
    indexOf(value)：返回数组中第一次出现给定元素的下标，如果不存在则返回 -1。
  取
    slice
      浅拷贝：slice()返回拷贝后的新数组
      一个参数a：开始取的索引：从a处开始截取
      两个参数a, b：取的范围的索引：取[a，b)范围的元素
  工具
    Array.from：将其他可迭代对象转换为数组
    Array.isArray：判断是否为数组
    fill(n)：返回数组内的所有位置被n填充的新数组
for (let i = 0; i < arr.length; i++) {
delete arr[i];
//删除数组元素，空出位置，数组长度不变
}
console.log(arr);
// [空 ×8]
arr.length = 0;
console.log(arr);
// []
const elements = ['Fire', 'Air', 'Water'];
console.log(elements.join());
// Expected output: "Fire,Air,Water"
console.log(elements.join(''));
// Expected output: "FireAirWater"
console.log(elements.join('-'));
// Expected output: "Fire-Air-Water"
const str = 'The quick brown fox jumps over the lazy dog.';
const words = str.split(' ');
console.log(words[3]);
// Expected output: "fox" （按空格分词）
const chars = str.split('');
console.log(chars[8]);
// Expected output: "k"
const strCopy = str.split();
console.log(strCopy);
// Expected output: Array ["The quick brown fox jumps over the lazy dog."]
const arr1 = [0, 1, 2, [3, 4]];
console.log(arr1.flat());
// expected output: Array [0, 1, 2, 3, 4]
// 参数是提取的深度，默认提取一层
const arr2 = [0, 1, [2, [3, [4, 5]]]];
console.log(arr2.flat());
// expected output: Array [0, 1, 2, Array [3, Array [4, 5]]]
console.log(arr2.flat(2));
// expected output: Array [0, 1, 2, 3, Array [4, 5]]
console.log(arr2.flat(Infinity));
// expected output: Array [0, 1, 2, 3, 4, 5]
const array = [1, 2, 3, 4, 5];
// Checks whether an element is even
const even = (element) => element % 2 === 0;
console.log(array.some(even));
// Expected output: true
const isBelowThreshold = (currentValue) => currentValue < 40;
const array1 = [1, 30, 39, 29, 10, 13];
console.log(array1.every(isBelowThreshold));
// Expected output: true
const array1 = [5, 12, 8, 130, 44];
const found = array1.find((element) => element > 10);
console.log(found);
// Expected output: 12
const words = ['spray', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter((word) => word.length > 6);
console.log(result);
// Expected output: Array ["exuberant", "destruction", "present"]
const arr = [1, 2, 3, 4, 5];
for (const item of arr){
console.log(item);
}
// 输出：1,2,3,4,5
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
console.log(array3);
// ["a", "b", "c", "d", "e", "f"]
const array4 = array1.concat(array2, '1', '2');
console.log(array4);
// ['a', 'b', 'c', 'd', 'e', 'f', '1', '2']
const a1 = [1, 2];
const a2 = [2, 3];
console.log([...a1, ...a2]);
// [1, 2, 2, 3]
console.log([...a1, 3, 4]);
// [1, 2, 3, 4]
const months = ['a', 'b', 'c', 'd'];
months.splice(1, 2);
// Inserts at index 1
console.log(months);
// Expected output: Array ['a', 'd']
const months = ['a', 'c', 'd', 'e'];
months.splice(1, 0, 'b');
// Inserts at index 1
console.log(months);
// Expected output: Array ['a', 'b', 'c', 'd', 'e']
const months = ['a','p','c','d'];
months.splice(1, 1, 'b');
// Inserts at index 1
console.log(months);
// Expected output: Array ['a', 'b', 'c', 'd']
const array1 = ['one', 'two', 'three'];
console.log('array1:', array1);
// Expected output: "array1:" Array ["one", "two", "three"]
const reversed = array1.reverse();
console.log('reversed:', reversed);
// Expected output: "reversed:" Array ["three", "two", "one"]
// 注意： reverse是破坏性的-- 它改变了原数组。
console.log('array1:', array1);
// Expected output: "array1:" Array ["three", "two", "one"]
let arr = [1, 4, 5, 13, 30, -7, 46, -5];
arr.sort();
console.log(arr);
//[-5, -7, 1, 13, 30, 4, 46, 5]
//默认以UTF-16 码元值升序排序，这会导致-5排在-7前面。
//升序
arr.sort((a, b) => a - b);
console.log(arr);
// [-7, -5, 1, 4, 5, 13, 30, 46]
//降序
arr.sort((a, b) => b - a);
console.log(arr);
// [46, 30, 13, 5, 4, 1, -5, -7]
//打乱顺序
arr.sort((a, b) => Math.random() - 0.5);
console.log(arr);
// [-5, 4, 5, 13, 30, 46, -7, 1]
const array1 = [1, 2, 3];
console.log(array1.includes(2));
// Expected output: true
const pets = ['cat', 'dog', 'bat'];
console.log(pets.includes('cat'));
// Expected output: true
console.log(pets.includes('at'));
// Expected output: false
const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];
console.log(beasts.indexOf('bison'));
// Expected output: 1
// Start from index 2
console.log(beasts.indexOf('bison', 2));
// Expected output: 4
console.log(beasts.indexOf('giraffe'));
// Expected output: -1
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
console.log(animals.slice());
// Expected output: Array ["ant", "bison", "camel", "duck", "elephant"]
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
console.log(animals.slice(2));
// Expected output: Array ["camel", "duck", "elephant"]
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
console.log(animals.slice(2, 4));
// Expected output: Array ["camel", "duck"]
console.log(animals.slice(1, 5));
// Expected output: Array ["bison", "camel", "duck", "elephant"]
console.log(Array.from('foo'));
// Expected output: Array ["f", "o", "o"]
// 也可以像map那样遍历
console.log(Array.from([1, 2, 3], (x) => x + x));
// Expected output: Array [2, 4, 6]
Array.from(document.querySelectorAll(".item"))
// 可以将伪数组转为数组，进而使用数组原型上的方法，比如map、includes...
console.log(Array.isArray([1, 3, 5]));
// Expected output: true
console.log(Array.isArray('[]'));
// Expected output: false
console.log(Array.isArray(new Array(5)));
// Expected output: true
const array1 = [1, 2, 3, 4];
// Fill with 0 from position 2 until position 4
console.log(array1.fill(0, 2, 4));
// Expected output: Array [1, 2, 0, 0]
// Fill with 5 from position 1
console.log(array1.fill(5, 1));
// Expected output: Array [1, 5, 5, 5]
console.log(array1.fill(6));
// Expected output: Array [6, 6, 6, 6]