jQuery.unique() but for normal Arrays….
It is stated in the manual that jQuery.unique() will only work for DOM objects. My problem was (well, first was to ready the manual correctly) that I needed to merge uniquely simple string arrays.
After banging my head for a long time I have finally found how to do it, and here is my solution
Array.prototype.unique = function()
{
var arrData = this;
var arrUnique= [];
for (var i = arrData .length; i--; )
{
var strData= arrData [i];
if ($.inArray(strData, arrUnique) === -1)
{
arrUnique.unshift(val);
}
}
return arrUnique;
}
Leave a Reply