Categories
JavaScript Answers

How to get the size of an array in an object with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *