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,809
  • 13
  • 27
  • 42
Dodo dodo
  • 59
  • 1
  • 9

3 Answers3

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

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

mrblue
  • 237
  • 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ć
  • 9,657
  • 4
  • 26
  • 47