Skip to content Skip to sidebar Skip to footer

Jquery: Why Doesn't Jquery.inarray() Work?

As shown in the image, I just do inArray on an array, looking for a node. and $previously_selected_node and the item at index 37 in $shapes are the same object.... so... why isn't

Solution 1:

Your object is not an array. $.inArray only work on array-like objects with a length and a set of properties named 0 through length - 1.

You need to search your non-array manually. For example, you could use a for / in loop to loop through all properties that actually exist and see if any of them match your object:

for (var key in $shapes) {
    if ($shapes[key] === yourObject) {
        //Match!
    }
}

Solution 2:

You're doing it the wrong way round. It's actually $.inArray(value, array).

And as others already stated: inArray is for arrays, not for objects.

Post a Comment for "Jquery: Why Doesn't Jquery.inarray() Work?"