Javascript Array remove(item)
Array.prototype.remove = function(item) { var index = this.indexOf(item); if (index !== -1) { this.splice(index, 1);/*from w ww. j a v a 2 s .c o m*/ } };
/**//w w w . jav a 2 s . c o m * Created by snekrasov on 07.05.2015. */ Array.prototype.remove = function (item) { var index = this.indexOf(item); while (index != -1) { this.splice(index, 1); index = this.indexOf(item); } };
Array.prototype.remove = function(item) { var j = 0;/*ww w. ja v a 2 s. c o m*/ while (j < this.length) { if (this[j] == item) { this.splice(j, 1); } else { j++; } } };
Array.prototype.remove = function (item) { var i = this.indexOf(item); if (i != -1)/*from w ww . j ava2 s .c om*/ this.splice(i, 1); };
Array.prototype.remove = function (item) { var index = this.indexOf(item); if (index >= 0) this.splice(index, 1); };
/*/*w w w. j a v a 2 s . c o m*/ Write a function that removes all elements with a given value. Attach it to the array type. */ var sampleArray = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1,'1']; Array.prototype.remove = function (item) { while (this.indexOf(item) >= 0) { this.splice(this.indexOf(item), 1); } return this; }; console.log(sampleArray.remove(1));
Array.prototype.remove = function(item) { var i,// www. jav a 2 s .co m len; for (i = 0, len = this.length; i < len; i += 1) { if (this[i] === item) { this.splice(i, 1); i -= 1; } } return this; }; var arr = [1, 2, 1, 4, 1, 1, 3, 4, 1, 111, 3, 2, 1, '1']; console.log('Original array'); console.log(arr); console.log(arr.length); console.log('Modified array without removed elements'); console.log(arr.remove(1)); console.log(arr.length);
//02.Write a function that removes all elements with a given value. //Attach it to the array type. //Read about prototype and how to attach methods. 'use strict';/*from w ww.ja va 2s.c om*/ Array.prototype.remove = function (item){ var result = [], i, len; for (i = 0, len = this.length; i < len; i += 1) { if (this[i] !== item) { result.push(this[i]); } } return result; }; var arr = [1,2,1,4,1,3,4,1,111,3,2,1,'1'], result; result = arr.remove(1); console.log(result);
Array.prototype.remove = function(item){ var index;/*from w ww . j a va 2 s . c om*/ while(1){ index=this.indexOf(item); if (index > -1) { this.splice(index, 1); console.log(this); }else{ break; } } };
Array.prototype.remove = function(item) { var i = $.inArray(item, this); if (i === undefined || i < 0) return undefined; return this.splice(i, 1); };
// TODO(scott): Move these to util functions. Polyfills don't // play very nice with RequireJS. Array.prototype.remove = function(item) { var index = this.indexOf(item); if (index !== -1) { this.splice(index, 1);//w w w .j a va 2 s .c om } };
Array.prototype.remove = function(item){ var arr = this.slice(0); for(var i=0;i<arr.length;i++){ if(arr[i] == item){ arr.splice(i,1);/*from www. ja v a 2 s. com*/ i--; } } return arr; }
Array.prototype.remove = function (item) { var index = this.indexOf(item); if (index < 0) { this.splice(index, 1);//from w ww .j a v a 2 s. c o m } return index; }
// Remove all items matches `item` in Array // TODO: Performance enhancement Array.prototype.remove = function(item) { var index;// w w w . j av a 2 s .c om while ((index = this.indexOf(item)) !== -1) { this.splice(index, 1); } return this; };
Array.prototype.remove = function(item) { var items = [] if (arguments.length > 1) { items = arguments;//from w w w . j av a 2 s. co m } else { items = [item]; } for (var i = 0; i < items.length; i++) { var index = this.indexOf(items[i]); if (index > -1) this.splice(index, 1); } return this; };
Array.prototype.remove = function(item){ var found = false; for(var i = 0; i < this.length; i++){ if (this[i] == item){ this.splice(i, 1);/* www . j a v a 2 s .co m*/ found = true; break; } } if (found == false){}//console.log("Couldn't find object to d?lete");} } Array.prototype.property = function(property){ properties = []; for(var i = 0; i < this.length; i++){ eval("properties.push(this[i]." + property + ");"); } return properties.flatten(); } Array.prototype.flatten = function(){ var flat_array = []; for(var i = 0; i < this.length; i++){ if (this[i].constructor == Array){ this[i] = this[i].flatten(); flat_array = flat_array.concat(this[i]); } else { flat_array.push(this[i]); } } return flat_array; }
Array.prototype.remove = function(item) { var index = -1; for ( var i = 0; i < this.length; i++) { if (this[i] == item) { index = i;/*ww w. ja v a2 s . c o m*/ } } var re = this[index]; if (index >= 0) { this.splice(index, 1); } return re; }