Skip to content

Instantly share code, notes, and snippets.

@riquellopes
Created June 17, 2012 20:06
Show Gist options
  • Save riquellopes/2945573 to your computer and use it in GitHub Desktop.
Save riquellopes/2945573 to your computer and use it in GitHub Desktop.
Simples solução para remover e adicionar elementos em um array.
/**
* Remove array element.
*/
Array.prototype.rm = function(value)
{
var arrays_s = this;
for( var i=0; i<this.length; i++)
{
var obj = this[i];
if( typeof obj === 'number' && obj == value )
this.splice(i, 1);
}//for
return this;
}//function
/**
* Adds array element.
*/
Array.prototype.add = function(value)
{
var pos = 0, exist = false;
for( var i =0; i< this.length; i++ )
{
var obj = this[i];
if( typeof obj === 'number' && obj == value )
{
pos = i;
exist = true;
}//if
}//for
if( !exist )
this.push(value);
return this;
}//function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment