You can get the length of an array in JavaScript using

arrayVariable.length

Roughly like this:

arrayVariable = [1, 2, 3, 4, 5]
console.log(arrayVariable.length);

--

In your code you have not created an array. allCars is an object.

You could get the number of properties in your custom object using Object.keys():

var numberOfKeys = Object.keys(allCars).length;

If you need this, I have concerns about the underlying data model, though.

--

You could also use a map data structure instead of an object and then use the size property.

let allCars = new Map();
allCars.set('Ford, 'Ka);
allCars.set('GM', 'Sonic');
allCars.set('Audi', 'A4');
console.log(allCars.size);

But, I think this is going down a very different route than the code you already shared.

Answer from JeffryHouser on Stack Overflow
🌐
Pipinghot
pipinghot.dev › find-the-length-of-an-array-in-typescript
Find the Length of an Array in TypeScript - Pipinghot.dev
September 29, 2025 - While .length remains the go-to solution for finding array lengths in TypeScript, understanding the nuances can help you cook up more robust and performant code.
Discussions

Typescript string | string[] find the array length
Exactly I want the stepData , when its string and when its string[] finding the length of array i am calling AJAX inside for loop More on stackoverflow.com
🌐 stackoverflow.com
How to check array length in typescript - Stack Overflow
I want to check array length in typescript! I can't find it when I search. More on stackoverflow.com
🌐 stackoverflow.com
December 1, 2019
how to use typescript to get the length of an array of objects
Although we certainly can't tell just from what you've posted, in addition to the suggestion that if it's an array you want the length property, it's possible that you haven't parsed the JSON string from the backend into it's Javascript representation, meaning that both Object.keys and the ... More on stackoverflow.com
🌐 stackoverflow.com
Check index array length
There was an error while loading. Please reload this page · Indexing, Array, Strict check More on github.com
🌐 github.com
18
April 16, 2020
🌐
Pipinghot
pipinghot.dev › snippet › check-if-an-array-has-length-in-javascript-typescript
Find the Length of an Array in TypeScript
September 29, 2025 - While .length remains the go-to solution for finding array lengths in TypeScript, understanding the nuances can help you cook up more robust and performant code.
🌐
Python Guides
pythonguides.com › find-the-length-of-an-array-in-typescript
How To Find The Length Of An Array In TypeScript?
June 23, 2025 - As a developer, you may often need ... based on the array size. TypeScript provides a straightforward way to obtain the length of an array using the length property....
🌐
Webdevtutor
webdevtutor.net › blog › typescript-finding-array-length
A Comprehensive Guide to Finding Array Length in TypeScript
Another way to find the length of an array in TypeScript is by using the Array.length method. This method returns the number of elements in an array.
🌐
Python Examples
pythonexamples.org › typescript › how-to-get-array-length
How to Get Array Length in TypeScript
Array.length property returns the length of this array. Finally, we shall print the value in length to standard output. let numbers: number[] = [1, 2, 3, 4, 5]; let length: number = numbers.length; console.log(`Length of array is: ${length}`);
Find elsewhere
🌐
xjavascript
xjavascript.com › blog › typescript-length-of-array
Understanding the Length of Arrays in TypeScript — xjavascript.com
In TypeScript, arrays are objects with a special property called length. The length property represents the number of elements in the array.
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › how-to-find-the-total-number-of-elements-in-an-array-in-typescript
How to find the Total Number of Elements in an Array in TypeScript ? - GeeksforGeeks
July 23, 2025 - The below methods can be used to accomplish this task: ... The length property is used to get the length or size of an array. It can be used to get the total number of elements stored in the array.
🌐
Webdevtutor
webdevtutor.net › blog › typescript-find-length-of-array
How to Find Length of an Array in TypeScript
The length property in TypeScript provides a convenient way to do this. The most straightforward way to find the length of an array in TypeScript is by using the length property.
🌐
Hyneks
hyneks.cz › blog › string-length-in-typescript
Get the exact string length in TypeScript | HynekS
August 26, 2022 - Still no success. Well, TypeScript actually can’t get the exact length of an array. The only data structure from which it can obtain length is a tuple, which is a list-like data structure with a fixed length.
Author: uhyo
🌐
xjavascript
xjavascript.com › blog › typescript-array-length
Mastering TypeScript Array Length: A Comprehensive Guide — xjavascript.com
In TypeScript, every array has a built-in length property. This property represents the number of elements in the array. It is a numeric value that can be accessed directly on the array object.
🌐
JavaScript in Plain English
javascript.plainenglish.io › check-list-size-in-typescript-2356df369a81
Check list Size in TypeScript. Understanding Arrays in TypeScript | by Pravin M | JavaScript in Plain English
November 26, 2024 - The length property reflects the number of elements in the array. It automatically updates as elements are added or removed from the array.
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-get-object-length
Get the length of an Object in TypeScript | bobbyhadz
Copied!interface Person { id: number; name: string; age: number; } const obj: Person = { id: 1, name: 'bobby hadz', age: 30 }; // 👇️ const length: number const len = Object.keys(obj).length; console.log(len); // 👉️ 3 ... We used the ...
🌐
npm
npmjs.com › package › typed-array-length
typed-array-length - npm
November 23, 2024 - Robustly get the length of a Typed Array, or false if it is not a Typed Array. Works cross-realm, in every engine, even if the length property is overridden.
      » npm install typed-array-length
    
Published: May 28, 2026
Version: 1.0.8
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › length
Array: length - JavaScript - MDN Web Docs
The length data property of an Array instance represents the number of slots in that array. The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array. It may be greater than the number of elements if the array is sparse.
🌐
GitHub
github.com › microsoft › TypeScript › issues › 38000
Check index array length · Issue #38000 · microsoft/TypeScript
April 16, 2020 - SuggestionAn idea for TypeScriptAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it addsAn issue which adding support for may be too complex for the value it adds ... const arr: House[] = .... // same as [] | House[] arr[0] // throw error if(arr.length > 0) { arr[0] // OK arr[200] // throw error } const arr2: [House, House] = ...
Author: microsoft