+ 1
How does below this code give answer 012 ?
var x=['a','b','c']; var arr="; For(var y in x){ arr+=y; } alert(arr);
1 Answer
+ 5
The output you are getting is due to using for-in loop improperly.
The for-in provides the index to each element in the array so you have to use x[y] to get the actual element.
By the way, you can use for-of loop to iterate over arrays.
https://code.sololearn.com/WDLlUq63kB8u/#js