maybe this is too much code but the problem is that cars variable on last line is always null even though I have if statement where I checking null and in that case I'm populating that variable, where in

console.log("1" +cars.length);

cars length is 3, so it's not null. Why this cars.length is not replicated on

console.log("2" +cars.length);

is everything ok with this

map function

in a way that I'm correctly populating cars variable?

Update:

when cars is correctly loaded with data- attribute I'm getting data in following format