// Array // to determine the base typetypeOf determines which reference type uses instanceoflet arr = [1, 2]
console.log(typeof arr) // object
console.log(arr instanceof Array) // true
Array.isArray(arr) // trueCheck the array with this // sort,reverseletAs = [0, 1, 5, 10, 15, 45, 55] console.log(as.sort()) // [0, 1, 10, 15, 45, 5, 55] sort converts the array values to strings for comparisonfunction compare(value1, value2) {
    if (value1 > value2) {
        return1}else if (value1 < value2) {
        return1}else {
        return0}} console.log(as.sort(compare)) // [0, 1, 5, 10, 15, 45, 55] console.log(as.sort(compare).reverse()) // [55, 45, 15, 10, 5, 1, 0letArry_2 = [0, 1, 5, 10, 15, 45, 55] arry_2.push(66) console.log(arry_2) // [0, 1, 5, 10, 15, 45, 55,66letArry_3 = [0, 1, 5, 10, 15, 45, 55] arry_3.pop() console.log(arry_3) // [0, 1, 5, 10, 15, 45] end delete // unshift header push inletArry_4 = [0, 1, 5, 10, 15, 45, 55] arry_4. Unshift (1) the console. The log (arry_4) / / [- 1, 0, 1, 5, 10, 15, 45, 55] / /shiftRemove the headletarry_5 = [0, 1, 5, 10, 15, 45, 55] arry_5.shift() console.log(arry_5) // [ 1, 5, 10, 15, 45, 55] // slice // The first argument is the start position, the second argument is the end position (but not the end position), if the second argument is not written, the default is until the end of the arrayletArry_6 = [0, 1, 5, 10, 15, 45, 55] console.log(arry_6.slice(1, 3))// [1, 5] // splice spliceletarry_7 = [0, 1, 5, 10, 15, 45, 55] arry_7.splice(1, Console. log(arry_7) // console.log(arry_7) // console.log(arry_7) // console.log(arry_7) 55] arry_7.splice(1, 0, 66, 77) // Add content console.log(arry_7) //[0, 66, 77, 10, 15, 45, 55] arry_7.splice(1, 2, 11, 22) // Replace array contents console.log(arry_7) //[0, 11, 22, 10, 15, 45, 55] // indexOf indexOfletArry_8 = [0, 1, 5, 10, 15, 1, 55] console.log(arry_8.indexof (1)) // 1'= = ='If not, -1 console.log(arry_8.lastIndexof (1)) //5 Start at the end and return the first matching value'= = ='If no, return -1 // iteration methodletArry_9 = [1, 2, 3, 4, 5] // every(): runs the given function on each item of the array, and returns each itemtrue, the returntrue
console.log(arry_9.every((item) => {
    return (item > 3)
})) // false// some(): Runs the given function on each item of the array, and returns one itemtrue, the returntrue
console.log(arry_9.some((item) => {
    return (item > 3)
})) // true// filter() runs the given function on each item of the array, returns the function returnstrueIf there are references in the array, just copy the pointer console.log(arry_9.filter((item) => {return (item > 3)
})) // [ 4, 5 ]
let ao = {a: 1, b: 2}
let bo = {a: 1, b: 2}
console.log(ao == bo) // false
console.log(ao === bo) //  false
let arry_10 = [ao, 2]
console.log(arry_10.filter((item) => {
    return (typeof item === 'object')
})) //[ { a: 1, b: 2 } ]
console.log(arry_10.filter((item) => {
    return (typeof item === 'object')
})[0] === ao) //true

// forEach performs a function on Each item of the array and returns no valueletarry_11 = [1, 2, 3, 4] arry_11.forEach(item => { item = item + 2 }) console.log(arry_11) // [ 1, 2, 3, 4] Arry_11. ForEach ((item, index, int, index, int, int, int, int, int, int, int, int, int) array) => { array[index] = item + 2 }) console.log(arry_11) // [ 3, 4, 5, 6 ]let arry_12 = [1, 2, 3, 4]
console.log(arry_12.map((item) => {
    return(item * 2)})) // [2, 4, 6, 8] // reduce iterates through all items and returns a value. Each value returned by this function will be the first argument in the next iteration and can be used for array summation, etclet arry_13 = [1, 2, 3, 4, 5]
console.log(arry_13.reduce((pre, next, index, array) => {
    return(pre + Next)}) // 15 // reduceRight is the same as reduce, but in reverse orderlet arry_14 = [1, 2, 3, 4, 5]
console.log(arry_14.reduceRight((pre, next, index, array) => {
    return (pre + next)
})) // 15
Copy the code