var arr = [1,2,3,4,,5,6]; console.log(arr.filter(item=>item<2)) Array.prototype.myFilter = function(fn){ if(typeof fn !== 'function'){ throw Error('must be a function') } const arr = this.slice(); let result = []; for(let i=0; i< arr.length; i++){ let currentResult = fn(arr[i]); if(currentResult){ result.push(arr[i]) } } return result; } console.log(arr.myFilter(item=>item<2))