Alex (SirShurf) Frenkel's Blog

A web log of a PHP professional

jQuery.unique() but for normal Arrays….

leave a comment »

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;
}

Advertisements

Written by Alex (Shurf) Frenkel

January 17, 2011 at 4:20 pm

Posted in Uncategorized

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

%d bloggers like this: