Javascript: Find duplicates in the array and delete from array.

Finding duplicates in array. Please go to groggyjava.

Deleting duplicates:

var duplicateCodes= [];
duplicateCodes.push(“ss”, “”, “ee”, “”,”ee”);  //inserting duplicates and some empty values.

duplicateCodes= duplicateCodes.filter(function(e){return e});  // removing empty values.
if(duplicateCodes.indexOf(“ee”) >= 0)  // checking if “ee” is already in the array
{
alert(“yes”);
}
alert(“Please remove \n” + duplicateCodes.join(‘\n’));

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s