Can someone explain the concept of empty and undefined in arrays to me?
Take a look at my code below:
const arr = []
arr[1]=1
arr[2]=2
arr[3]=3
arr[5]=5
console.log(arr[4])// console: undefined
console.log(arr)// console: [empty, 1,2,3,empty,5]
I am confused about why console.log(arr[4]) returns undefined while index 4 of console.log(arr) is actually empty. Can anyone shed light on this for me?
Thank you in advance for your help.