-2

If I have a JavaScript object, say

data
:
Array[1]
 0
 :
 Object
  section
  :
  Array[6]
  tool
  :
  Array[6]
  wellcon
  :
  Array[6]
  welltra
  Array[6]

from this how i get the section length. i try like

data.section.length

but this is wrong. what is the wrong in my syntax?

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
manu p
  • 149
  • 1
  • 1
  • 13

3 Answers3

1

Try data[0].section.length I think it is answer

nartoan
  • 368
  • 2
  • 9
0

Try this one

 Object.keys(data).length

or you can find it in another way

Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
    if (obj.hasOwnProperty(key)) size++;
}
return size;
};

var size = Object.size(data);//length of the data
Gayathri Rajan
  • 369
  • 1
  • 6
  • 18
0

I guess you are looking for this:

Object.keys(data.section).length

or

Object.entries(data.section).length

but this way is experimental thing, described here

Karlen
  • 1,294
  • 13
  • 20