I've recently started learning programming and JavaScript, but I'm struggling to access data within an array. Below is a snippet of my code:
global.arr = [];
var id = 12;
for (var i=0; i<5; i++) {
arr.push(id);
id++;
}
console.log(arr);
console.log(arr[0]);
My question is, how can I properly access the data in this array? What am I doing wrong here?
Despite making changes, my current code still isn't working as expected:
var arr = [];
var id = 12;
for (var i=0; i<5; i++) {
arr.push(id);
id++;
}
console.log(arr);
console.log(arr[0]);