JQuery

Javascript Dedup an Array

TAGs: 0 Comment

Posted By: eligeske on in JQuery

Here is a simple javascript function do remove the duplicate values in an array. It worked very well for what I needed it for, although it may not be full proof for your application.

function dedupArray(array)
{
array.sort();
var cnt = array.length – 1;
var i=0;
var keepers = new Array();
while(i <= cnt){
if(array[i] != array[i + 1]){
keepers.push(array[i]);
i++;
}else{
array.shift();
}
cnt = array.length – 1;
}
return keepers;
}

0 Responses to "Javascript Dedup an Array"

"SHARING IS CARING"

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Learning DHTMLX Suite UI

Learn the foundation of the DHTMLX Suite quickly while building a single page application with multiple components in harmony.

Popular post