If you want to find out the length of an array in JavaScript, you can simply use
arrayVariable.length
For example:
arrayVariable = [1, 2, 3, 4, 5]
console.log(arrayVariable.length);
--
In your code snippet, it appears that allCars is not actually an array but an object.
To get the number of properties in your custom object, you can utilize Object.keys():
var numberOfKeys = Object.keys(allCars).length;
If this is something you require, there might be some concerns regarding the data model being used.
--
An alternative approach would be to utilize a map data structure instead of an object and access the size property.
let allCars = new Map();
allCars.set('Ford', 'Ka');
allCars.set('GM', 'Sonic');
allCars.set('Audi', 'A4');
console.log(allCars.size);
However, this route may lead you in a different direction compared to the current code you are working with.