FrontEnd

JQuery Array remove by value (push, pop, slice 이외의 기능을 쓰고 싶을 때)

seowooJeong 2021. 3. 26. 12:15
//remove function을 만든다.
Array.prototype.remove = function(v) { 
	this.splice(this.indexOf(v) == -1 ? this.length : this.indexOf(v), 1); 
   }
   
// ex) var arr = [];
// arr.push('a');
// arr.push('b');
// arr.push('c');

arr.remove('b');
console.log(arr);

//result ['a','c']