Cannot access valid array in react keep getting cannot read properties undefined

I try to access an array events : [data,data,data,length] with the following code I tried the following 3 things but kept getting these errors respectively for the code below:

console.log(events.length)

let def = 0;
let i = 0;

while(def !== undefined){
    def = events[i];
    console.log(events[i]);
    i++
}

for(i = 0; i < events.length; i++){
    console.log(events[i]);
}

Cannot read properties of undefined (reading 'length'),
Cannot read properties of undefined (reading '0'),
Cannot read properties of undefined (reading 'length')

Getting the same error when using array.forEach or array.map