You need to understand about "in" operator first. The in operator returns true if the specified property is in the specified object or its prototype chain or in an Array. How to use this for Array (sample reference here ):
// Arrays
let trees = ['redwood', 'bay', 'cedar', 'oak', 'maple']
0 in trees // returns true
3 in trees // returns true
6 in trees // returns false
'bay' in trees // returns false (you must specify the index number, not the value at that index)
'length' in trees // returns true (length is an Array property)
Symbol.iterator in trees // returns true (arrays are iterable, works only in ES2015+)
// Predefined objects
'PI' in Math // returns true
// Custom objects
let mycar = {make: 'Honda', model: 'Accord', year: 1998}
'make' in mycar // returns true
'model' in mycar // returns true
What you're checking on Array is the key, which is its index. You should use find method in array to find any values instead of "in":
const arrays=[ 1 , 2, 3 ];
const arrays_1=[ 1 , 2, 3, 3, 4, 3 ];
const found = arrays.find(el => el === 3); // it will return the first value if it matches the condition.
const found_all = arrays_1.filter(el => el === 3); // will give all the matching values.
this.array[z]is not the arrayidis a key (in an array an index) of an element in your array when you useinonthis.array[z]. You're essentially asking "is 3 a key in the number 1?", which doesn't really make sense since1is a primitive and not an object - use.includes()if you want to check if a value is in an array.for (let .. of ..)to iterate over arrays.