Categories
JavaScript Answers

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

Spread the love

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", cd: "c01", dd: "d01" },
    { id: "s02", cd: "c02", dd: "d02" },
  ],
};

console.log(st.itemB.length);

to get the length of the st.itemB array property with st.itemB.length.

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 *