Cherry Cherry - 1 year ago 138
jQuery Question

How to know whether the object contains in my Array List of jquery?

In my Ajax success function data, I am getting a list of objects. I have one more array list with objects which are of same type. How to write a condition to check if that object contains in my list?

//In my Ajax Success function
$.each(data, function(index, item) {
//This is my another array list
var target = [];
target =;
//Need to check the condition whether the above "item" is in my above array list

I am doing something like this, its not working

if (target.indexOf(item) !== -1) {
//item is not present in the above target array list
} else {

Answer Source

From How to determine if object is in array

function containsObject(obj, list) {
var i;
for (i = 0; i < list.length; i++) {
    if (list[i].YourId === obj.Id) {
        return true;

return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download