Javascript if in x [duplicate]

Use indexOf which was introduced in JS 1.6. You will need to use the code listed under “Compatibility” on that page to add support for browsers which don’t implement that version of JS.

JavaScript does have an in operator, but it tests for keys and not values.

p.s. original answer is from 2011, now it’s supported by all browsers in use. https://caniuse.com/?search=indexof

Leave a Comment