0

I'm supposed to read certain data from a JSON file :

enter image description here

I'm able to print the correct value for :

console.log('data1 ' + data.entry[0].id);
console.log('data2 ' + data.entry[0].content.properties.yyn);

However, I want to find the length of the properties instead of reading each entity inside properties. I tried:

console.log('data2 ' + data.entry[0].content.properties.length); 

It did not work!

user4157124
  • 2,533
  • 12
  • 24
  • 39
Dodo dodo
  • 59
  • 1
  • 8

3 Answers3

-1
console.log('data2 ' + Object.keys(data.entry[0].content.properties).length);
uiTeam324
  • 1,085
  • 9
  • 33
-1

If you want to know how many keys your object has, use Object.keys(obj).length

mrblue
  • 217
  • 1
  • 12
-1

Properties is an object, not an array. You can count the length of its keys:

const numOfProps = Object.keys(data.entry[0].content.properties).length;
Roberto Zvjerković
  • 8,622
  • 4
  • 23
  • 42