0

i dont understand this alert in js

var x = [1,2,3]; alert(x[x[x.length%2]]); //answer is:3. //but how do i read this? //i would first read the modulo, result =1; //then i dont know what kind of x i should take of this array. and where is the „3“ resulting from? 😫

15th Dec 2019, 6:42 PM
Mylisa_beth
Mylisa_beth - avatar
5 Answers
+ 4
Youre welcome ^_^
15th Dec 2019, 7:02 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 3
3 comes from the x array
15th Dec 2019, 6:48 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 2
so x.length%2 = 1 that makes it x[x[1]] x[1] is 2 that makes it x[2] and x[2] is 3
15th Dec 2019, 6:47 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 1
oh jesus!!! thank you for your help and clear explanation!!! 👍👍💪👍👍
15th Dec 2019, 6:50 PM
Mylisa_beth
Mylisa_beth - avatar
+ 1
reading from inside out. 😃
15th Dec 2019, 6:51 PM
Mylisa_beth
Mylisa_beth - avatar