What is the correct fix?
const list = ['a', 'b'];
if ('a' in list) {
console.log('found');
}
- Test membership with
list.includes('a') - Test membership with
list.contains('a') - Change the array into a plain object
- Compare directly with
list == 'a'
in tests keys ('0','1') on an array, not the values stored in it.