Home >Web Front-end >JS Tutorial >Add append and remove functions to data_javascript skills

Add append and remove functions to data_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:25:431369browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn