0

Can't figure out why this always returns false:

var filter_clients = [25,351];
var data = 351;
console.log(filter_clients);
console.log(data);
if(data in filter_clients) console.log('in');
else console.log('out');

fiddle

Works for a Living
  • 1,262
  • 2
  • 19
  • 44

1 Answers1

1

When working with arrays, in operator applies to index and not to values. Examples:

0 in filter_clients //true
1 in filter_clients //true
2 in filter_clients //false

This is a way to implement what you're trying to do

filter_clients.indexOf(data) != -1
Claudio Redi
  • 67,454
  • 15
  • 130
  • 155