The code I'm referencing comes from this answer:
Array.prototype.getUnique = function(){
var u = {}, a = [];
for(var i = 0, l = this.length; i < l; ++i){
if(u.hasOwnProperty(this[i])) {
continue;
}
a.push(this[i]);
u[this[i]] = 1;
}
return a;
}
What is the purpose of hasOwnProperty
here? I've ran a version of the method that does not use it and it works just the same:
Array.prototype.getUnique = function(){
var u = {}, a = [];
for(var i = 0, l = this.length; i < l; ++i){
if(u[this[i]] !== undefined) {
continue;
}
a.push(this[i]);
u[this[i]] = 1;
}
return a;
}