'How to create custom find method?
I'm trying to create custom find method using Array.prototype, I tried a lot of way but i just couldn't break the loop for the first match:
let arr = ["Bill", "Russel", "John", "Tom", "Eduard", "Alien", "Till"];
Array.prototype.myFind = function (callback) {
for (let i = 0; i < this.length; i++) {
callback(this[i], i, this);
}
};
arr.myFind((element, index, array) => {
if (element[0] === "T") {
console.log(`This is ${element} in index of ${index} in array ${array}`);
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
