0

I've a Javascript array and pushing the elements for later usage like this:

var array = [jQuery('.first').eq(0)];

Now if I try to check if the same element in array exists, it returns -1

jQuery.inArray(jQuery('.first').eq(0), array)

What is the perfect way to find if the object exists in array or not.

Manish Jangir
  • 5,329
  • 4
  • 42
  • 75
  • That provides if objects are equal or not but how to find if the object is in array or not without using for loop – Manish Jangir Jan 19 '17 at 10:58
  • 1
    @Manish, that's because there is no way to coerce `inArray()` into making a special case for jQuery objects. Therefore, you'll have to write a custom loop. Of course, you can wrap that loop in a function if you're so inclined. – Frédéric Hamidi Jan 19 '17 at 11:00
  • Ok Finally I did it using array iteration with for loop – Manish Jangir Jan 20 '17 at 06:06

0 Answers0