Showing posts with label jquery. Show all posts
Showing posts with label jquery. Show all posts

Saturday, July 28, 2012

Array Unique in Jquery

Here is the code to remove the duplicates from an array in Jquery.

in below code countries is an array which contains all the elements.

var unique_countries = countries.filter(function(itm,i,countries){return i == countries.indexOf(itm);});

Array Difference in Jquery

Hi

Here is the snippet to find the difference between the two arrays in JQUERY.

var array1 = ["test1", "test2","test3", "test4"];
var array2 = ["test1", "test2","test3","test4", "test5", "test6"];

var _array = new Array();

_array = jQuery.grep(array2, function (item) {
     return jQuery.inArray(item, array1) < 0;
});