Sometimes, we want to get the size of an array in an object with JavaScript.
In this article, we’ll look at how to get the size of an array in an object with JavaScript.
How to get the size of an array in an object with JavaScript?
To get the size of an array in an object with JavaScript, we use the length property.
For instance, we write
const st = {
itema: {},
itemb: [{ id: "s01" }, { id: "s02" }],
};
console.log(st.itemb.length);
to get the st.itemb array.
And then we use its length property to get the size of the array.
Conclusion
To get the size of an array in an object with JavaScript, we use the length property.