0
console.log(response.key);
console.log(answersNeedToBeBoolean);
console.log($.inArray(response.key, answersNeedToBeBoolean));

Output in console:

177
[8, 177, 179, 181]
-1

These seems pretty cut and dry to me. Clearly 177 is in the array. How on earth could it not find it?

3
  • can you try console.log(jQuery.isArray(answersNeedToBeBoolean)) Commented Apr 8, 2015 at 4:51
  • It works if the values are as you've stated. There's something more to it than that. Commented Apr 8, 2015 at 4:51
  • One reason could be answersNeedToBeBoolean is an array of int values where as response.key is a string so try console.log($.inArray(+response.key, answersNeedToBeBoolean)); Commented Apr 8, 2015 at 4:52

1 Answer 1

3

See, if response.key is a string '177' output would be -1

177
[8, 177, 179, 181]
-1

Fiddle

If its an integer 177 output would be 1.

Use JSON.parse() or parseInt(), as you have an integer array.

$.inArray(JSON.parse(response.key), answersNeedToBeBoolean)

Updated Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - this was the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.