I'm trying to add an any
method to Array
.
Array.prototype.any = (pred) => {
for(const item of this) {
if (pred(item)) {
return true
}
}
return false
}
console.log([1, 2, 3].any(num => num === 3))
...but I'm getting the error:
Uncaught TypeError: undefined is not a function
at Array.any (array.js:4)
at array.js:13
I was expecting true
to be printed to to the console. What did I do wrong?