Check a value Exist in Array in Jquerry
Check Value in Array / return true false
var found = $.inArray(value, Array) > -1;
Removing Duplicates and push into a new Array.
var ResArray =["anil", "Kumar","anil"];
$.each($.unique(ResArray), function(i, el){
uniqueNames.push(el);
});
Out Put:
uniqueNames=["Anil", "Kumar"];
Pick The Extra users After Comparing 2 Arrays:
var PickedUsers=["1","2"];
var uniqueNames=["2"];
var extraUsers=[];
jQuery.grep(PickedUsers, function (el) {
if (jQuery.inArray(el, uniqueNames) == -1)
extraUsers.push(el);
});
Out Put:
extraUsers=["1"];
var found = $.inArray(value, Array) > -1;
Removing Duplicates and push into a new Array.
var ResArray =["anil", "Kumar","anil"];
$.each($.unique(ResArray), function(i, el){
uniqueNames.push(el);
});
Out Put:
uniqueNames=["Anil", "Kumar"];
Pick The Extra users After Comparing 2 Arrays:
var PickedUsers=["1","2"];
var uniqueNames=["2"];
var extraUsers=[];
jQuery.grep(PickedUsers, function (el) {
if (jQuery.inArray(el, uniqueNames) == -1)
extraUsers.push(el);
});
Out Put:
extraUsers=["1"];
Comments