0
Hello, I’m doing a class extension Array
where I want to create a method that checks whether a property exists within the Array
: thus:
Array.prototype.contains = function(element){
for(let e of this)
if(e === element)
return true;
return false;
}
The problem is that I cannot access the object of the Array instance when using this method:
[1,2,3,4].contains(3); // deveria retornar true
what I need to do to access the instance of the array in this situation?
console.log([1,2,3,4].contains(3));
is returningtrue
.– Sam
hm... huh I got it at the time to write here unintentionally? kkk
– LeandroLuk
I seem to have solved the problem by writing my code here... the solution is the one already described as @Sam said
– LeandroLuk