You need to sign in to do that
Don't have an account?

find length of attribute in lightning
I have a json array as follows in lightning component controller.
var providerObj = [];
providerObj=[{
"specialties": [
{
"type": "specialty",
"name": "Cardiology",
"id": "839"
},
{
"type": "specialty",
"name": "Pediatric Cardiology",
"id": "824"
},
{
"type": "specialty",
"name": "Pediatric Cardiothoracic Surgery",
"id": "707"
}
],
"procedures": [
{
"type": "procedure",
"name": "Established Patient Office Visit (Interventional Cardiology)",
"id": "1735"
},
{
"type": "procedure",
"name": "Established Patient Office Visit (Pediatric Cardiology)",
"id": "1768"
},
{
"type": "procedure",
"name": "Office Consultation ONLY for new or established patients, no testing (Cardiology)",
"id": "1499"
}
],
"providers": [
{
"type": "facility",
"name": "Eastern CT Cardiology Diagnostic",
"id": "0007302322",
"default_procedure": null
},
{
"type": "facility",
"name": "NY Comprehensive Cardiology, LLC",
"id": "0007816766",
"default_procedure": null
},
]
}];
component.set("v.allResults",providerObj);
Here allResults attribute is of the following type
<aura:atttrbute name="allResults" type="Object"/>
I want to get the length of specialities , procedures and providers and also the total number of JSON records.
I am doing like this in controller
var arrayCount = providerObj.length;
var specCount = providerObj.specialities.length;
But whatever I do I am not getting the count of records.
Please help me regarding this
tina
var providerObj = [];
providerObj=[{
"specialties": [
{
"type": "specialty",
"name": "Cardiology",
"id": "839"
},
{
"type": "specialty",
"name": "Pediatric Cardiology",
"id": "824"
},
{
"type": "specialty",
"name": "Pediatric Cardiothoracic Surgery",
"id": "707"
}
],
"procedures": [
{
"type": "procedure",
"name": "Established Patient Office Visit (Interventional Cardiology)",
"id": "1735"
},
{
"type": "procedure",
"name": "Established Patient Office Visit (Pediatric Cardiology)",
"id": "1768"
},
{
"type": "procedure",
"name": "Office Consultation ONLY for new or established patients, no testing (Cardiology)",
"id": "1499"
}
],
"providers": [
{
"type": "facility",
"name": "Eastern CT Cardiology Diagnostic",
"id": "0007302322",
"default_procedure": null
},
{
"type": "facility",
"name": "NY Comprehensive Cardiology, LLC",
"id": "0007816766",
"default_procedure": null
},
]
}];
component.set("v.allResults",providerObj);
Here allResults attribute is of the following type
<aura:atttrbute name="allResults" type="Object"/>
I want to get the length of specialities , procedures and providers and also the total number of JSON records.
I am doing like this in controller
var arrayCount = providerObj.length;
var specCount = providerObj.specialities.length;
But whatever I do I am not getting the count of records.
Please help me regarding this
tina
This above statement should give you the expected length of the providerObj array which is 1 as it has a single element which is an object.
However, to get the length of the property 'specialities' , you must write it like:
providerObj[0] will return the first element of the array which is an object and after that you should be able to access the specialities property.
Thanks,
Deekshant
All Answers
This above statement should give you the expected length of the providerObj array which is 1 as it has a single element which is an object.
However, to get the length of the property 'specialities' , you must write it like:
providerObj[0] will return the first element of the array which is an object and after that you should be able to access the specialities property.
Thanks,
Deekshant
Thanks, This worked.