Resolve the issue

why this code shows undefined in console in the array arr2?
40%20AM 27%20AM

The first iteration of the loop we have j = 2.
So when we try to access arr1[2] it is evaluated as undefined because arr1 only has 2 values: arr[0] and arr[1].

So you end up adding undefined to arr1 and when we reach j=0 we quit the loop so arr1[0] is never accessed. <-- My apologies I did not see the equals sign so the loop indeed accesses the 0th element of the array.

1 Like

@camperextraordinaire it was just a simple try /catch thing …to recheck how the code works.