cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

how to take out the length of the json elements?

adityaku
Newbie

how to take out the length of the json elements?

for example:

var text =

{"employees":[

    {"firstName":"John", "lastName":"Doe", "Age":"24", "Gender":"M"},

    {"firstName":"Anna", "lastName":"Smith", "Age":"25", "Gender":"F"},

    {"firstName":"Peter", "lastName":"Jones", "Age":"24", "Gender":"M"},

    {"firstName":"Aditya", "lastName":"Kumar", "Age":"25", "Gender":"M"},

    {"firstName":"Shashank", "lastName":"Rai", "Age":"24", "Gender":"M"},

    {"firstName":"Harshit", "lastName":"Chowdhary", "Age":"24", "Gender":"M"},

    {"firstName":"Reetam", "lastName":"Kansabanik", "Age":"26", "Gender":"M"},

    {"firstName":"Priyanka", "lastName":"Kumari", "Age":"20", "Gender":"F"},

    {"firstName":"Nidhi", "lastName":"Tiwari", "Age":"22", "Gender":"F"},

    {"firstName":"Priyanshu", "lastName":"Mehta", "Age":"23", "Gender":"M"},

    {"firstName":"Preeti", "lastName":"Gupta", "Age":"24", "Gender":"F"},

    {"firstName":"Virat", "lastName":"Kohli", "Age":"28", "Gender":"M"},

    {"firstName":"Mahendra", "lastName":"Dhoni", "Age":"24", "Gender":"M"},

    {"firstName":"Harshita", "lastName":"Rai", "Age":"23", "Gender":"F"},

    {"firstName":"Ishan", "lastName":"Verma", "Age":"24", "Gender":"M"},

    {"firstName":"Moen", "lastName":"Ali", "Age":"24", "Gender":"M"},

    {"firstName":"Muktesh", "lastName":"Chandra", "Age":"32", "Gender":"M"},

    {"firstName":"Vinod", "lastName":"Patel", "Age":"28", "Gender":"M"}

]}

In the above example we have 18 elements, but how take the length of var text in case of JSON elements in thingworx?

3 REPLIES 3

Re: how to take out the length of the json elements?

in normal outside thingworx, we use:

Object.keys(text).length;


But this is not working.

Re: how to take out the length of the json elements?

Try this. It will do.

var result = text["employees"].length;

Re: how to take out the length of the json elements?

Thanks Praveen

Announcements

Check out the upcoming Expert Session: Understanding ThingWorx Navigate Licensing in Community "Customer Events" section.