Check if an object exists in a JavaScript array using jQuery
If you would like to find an object in existing JavaScript array, below is the sample example.
var list= [];
var obj1 = {id:1,name:'paramesh'};
var exist=$.grep(list, function(obj) {
return obj.name === 'john';
});
if(exist.length===0){
list.push(obj1);
}
No comments:
Post a Comment