数组的常见方法

93 阅读1分钟
 1. 数组常见方法
          a. 修改原数组的
            unshift  push  shift  pop  splice   reverse   sort  fill
             
          b. 不修改原数组
            indexOf  includes concat  slice  join   
            flat()   toReversed()  toSorted()  toSpliced()  with()  

          c. 数组的遍历方法
            forEach map filter some every reduce reduceRight 

            find  findIndex  findLast   findLastIndex

             Array.prototype.toReversed = function(index,value){
                let newList = JSON.parse(JSON.stringify(this));
                return newList.reverse();
            }

            Array.prototype.with = function(index,value){
                this.splice(index,1,value);
            }

          b. 不修改原数组
            indexOf  includes concat  slice  join   
            flat()   toReversed()  toSorted()  toSpliced()  with()  

          c. 数组的遍历方法
            forEach map filter some every reduce reduceRight 

            find  findIndex  findLast   findLastIndex
 
             Array.prototype.toReversed = function(index,value){
                let newList = JSON.parse(JSON.stringify(this));
                return newList.reverse();
            }

            Array.prototype.with = function(index,value){
                this.splice(index,1,value);
            }
            
  2.对象常见方法
       a.获取对象的属性名
       const key = Object.keys(对象名)  返回数组
       
       b.获取对象的值
       const value = Object.values(对象名)  返回数组