手写数组的方法

<body>
    <script>
      // map
      // Array.prototype.Mymap = function (callback) {
      //   let newArr = []
      //   // console.log(this); // arr [1,5,6]
      //   for (let i = 0; i < this.length; i++) {
      //     newArr.push(callback(this[i], i, this))
      //   }
      //   return newArr
      //   // callback()
      // }

      // let arr = [1, 5, 6]
      // arr.Mymap(function (item, index, array) {
      // })
      // console.log(res)
      // Array.prototype.myForEach = function (callback) {
      //   // console.log(this); // [1,5,6]
      //   // console.log(function(){});
      //   for (let i = 0; i < this.length; i++) {
      //     callback(this[i], i, this)
      //   }
      // }
      // let arr = [1, 5, 6]
      // const res = arr.myForEach(function (item, index, array) {
      //   // console.log(item);
      //   // console.log(index);
      //   console.log(array)
      //   // return 1
      // })
      // console.log(res)
    </script>
  </body>

 

posted @ 2022-11-29 20:11  噢噢噢J  阅读(19)  评论(0编辑  收藏  举报