● 값으로 지우기
Array.prototype.removeByValue = function() {
if(!Array.prototype.indexOf) {
Array.prototype.indexOf = function(what, i) {
i = i || 0;
var L = this.length;
while (i < L) {
if(this[i] === what) return i;
++i;
}
return -1;
};
}
var what, a = arguments, L = a.length, ax;
while (L && this.length) {
what = a[--L];
while ((ax = this.indexOf(what)) !== -1) {
this.splice(ax, 1);
}
}
return this;
};
● 인덱스로 지우기
Array.prototype.removeByIdx = function(idx) {
return (idx<0 || idx>this.length) ? this : this.slice(0, idx).concat(this.slice(idx+1, this.length));
};
'웹 개발 > 스크립트 일반' 카테고리의 다른 글
| 숫자 뒤 % 붙이기. (1) | 2017.11.30 |
|---|---|
| 숫자 외 몇몇 키 만 입력받기 (0) | 2017.11.30 |
| String to Date (0) | 2017.11.29 |
| Object to XML (0) | 2013.11.07 |