+ 1

Plz explain js code

var arr=[9,8,7,6]; console.log(1 in arr) //true console.log(9 in arr) //false Why 1 in arr is true

3rd Oct 2019, 11:23 AM
7n4n03n
7n4n03n - avatar
1 Odpowiedź
+ 7
7n4n03n , with "in" you are checking for element in the array if it's present in certain position. So there is an element on position 1, but there's no element on position 9 (the last position of the array is 3).
3rd Oct 2019, 11:36 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar