P
ROTOTYPE
I'm Not Only The Prototype, I'm Also A Member.
home
▪
stats
▪
search
▪
linkback
▪
about
▪
FAQ
| user: guest,
login
,
register
Array
:
addDistinct(val)
author:
daafy
[+]
,
Submitted: 09.17.01 4a
// just verify an element is not already in before adding one. array.prototype.addDistinct = function(val){ for(var i = 0; i < this.length; i++) if(val == this[i]) return trace("element already in"); return this.push(val); }
usage
var myArray = new Array("Tic", "Tac", "Toe"); myArray.addDistinct("Tac") // => doesn't push myArray.addDistinct("Jim") // => all right this example is with strings but is of course ok with objects & else also.
Add Comment
[+]
›opyleft 2001-2010. Layer51 is: Jaime Prado.
@