数组find原理


let arr = [20, 40, 60];
Array.prototype.myfind = function (fn) {
  for (let i = 0; i < this.length; i++) {
    let flag = fn(this[i],i,this);
    if (flag) {
      return this[i];
    }
  }
};

let r = arr.find(item=>item==40);
console.log(r)

数组from 原理


let str = "hello";
Array.myfrom = function () {
  let arr = [];
  Array.prototype.forEach.call(arguments, function (item) {
    arr.push(item);
  });
  return arr;****
};

let r = Array.myfrom(str)
console.log(r)



带你入门前端
38 声望2 粉丝

通俗易懂,言简意赅授课