Check for Duplicates in an array

This Function will check for duplicate entries in an array and return true or false

For Single Dimensional Array
Array.prototype.chkforDuplicates = function (value)
// Returns true if the passed value is found in the
// array. Returns false if it is not.

{
var i;
var ctr = 0;
for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i] == value) { return true; } } return false; }; For Multi Dimensional Array
Array.prototype.chkforDuplicates = function (value,Idx)
// Returns true if the passed value is found in the
// array. Returns false if it is not.

{
var i;
var ctr = 0;
for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i][Idx] == value) { return true; } } return false; }; ong>Note: Idx is the Value of the Column You want to check for duplicates

6 Replies to “Check for Duplicates in an array”

  1. Pingback: Randy Sizemore
  2. Hi, can you give an example of the Duplicates in an array function using a textbox and a drop down. Im using a function to add to the drop dwon menu the value from the text box but i need to check if the value already exist in the drop down.

    thanks in advance

Leave a Reply to Marko Cancel reply

Your email address will not be published. Required fields are marked *