Home > Web Front-end > JS Tutorial > body text

Add append and remove functions to data_javascript skills

WBOY
Release: 2016-05-16 19:25:43
Original
1344 people have browsed it

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template