手写lodash库里面的head函数

51 阅读1分钟

手写loadsh函数的第二天

 <script>
      const arr = [1, 2, 3];
      function head(arr) {
        const newArr = [];
        if (newArr != []) {
          for (let i = 0; i < arr.length; i++) {
            return arr[0];
          }
        }
      }
      console.log(head(arr));
    </script>