Home >Web Front-end >JS Tutorial >Add append and remove functions to data_javascript skills
Array.prototype.append = function(str) {
var newArr = new Array(str);
return this.concat(newArr);
}
Array.prototype.remove = function(str) {
var retArr = new Array();
for(i = 0; i if(this[i] != str) retArr = retArr .append(this[i]);
}
return retArr;
}
Array.prototype.hasItem = function(str) {
for(var i = 0; i if(this[i] == str) {
return true;
}
}
return false;
}
Tip: JavaScript does not have add, but it has push and unshift methods. It does not have remove, but it has pop and shift methods. If not, there is also splice method