0

If I do console.log(myObject) the result like this :

enter image description here

I want to calculate the length

I try myObject.lenght, but it does not work

How can I solve this problem?

Seems this must convert first to normal object

moses toh
  • 12,344
  • 71
  • 243
  • 443
  • 6
    Objects don't have a 'length'. Assuming you mean that you want to know how many properties are stored in the object you can use `Object.keys(myObject).length` – Rory McCrossan Mar 22 '18 at 11:41
  • I was assuming your variable type based on the lack of information provided. Could you please show the actual contents of the variable in your question - and also not as an image as they are useless. Please copy+paste the code directly in to the question – Rory McCrossan Mar 22 '18 at 11:48
  • @SuccessMan has failed to read the object at the correct time. – Teemu Mar 22 '18 at 11:48
  • Possible duplicate of: [How to get object length](https://stackoverflow.com/q/5533192/1369473) – Fr0zenFyr Mar 22 '18 at 12:02

2 Answers2

5

In JS, objects don't have a length property, you can use the Object.keys(--your desired object--) and get its length like this Object.keys(myObject).length. I hope it helps.

Waleed Iqbal
  • 1,308
  • 19
  • 35
0

Object.keys will return an array containing all the keys in your object, which you must pass as parameter. Get the length of this array instead.

Eigendrea
  • 320
  • 4
  • 14