In Javascript an Array can act as a stack (push/pop) in which you can push new items after checking they're not already in the stack.
var emailAddrs = [];
var item;
for(var i = 0; i < 5; i++){
item = document.getElementsByName("email"+i)[0].value;
if(! emailAddrs.contains(item))
emailAddrs.push(item);
}
UPDATE
Once you have your array build, you can then use that as a basis to do other operations. Using the length
property of the array, you can check how many items are in the array vs how many you expected to see.
You could also push identical items into another array and use this information to let the user know what needs changing
UPDATE 2
I just realised that the contains method I use is created by adding the following code:
Array.prototype.contains = function(obj) {
var i = this.length;
while (i--) {
if (this[i] === obj) {
return true;
}
}
return false;
}
This then creates a contains
method to each array object.
If you're using jQuery, you can also do $.inArray(value, array)