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

How to get the length of a attribute of type " map" in lightning controller
Hi ,
How to get the length of a attribute of type " Map" from lightning controller.
Component:
Controller:
The above code result to "undefined". Actually I have to get "5" as myMap has 5 elements. Can you please help in getting this.
Thanks in advance.
Regards,
Naveen.
How to get the length of a attribute of type " Map" from lightning controller.
Component:
<aura:attribute name="IndexMap" type="Map" default="{ 'Draft':1, 'Pending':2, 'NeedInfo':3, 'Resolved':4, 'Closed':5}"/>
Controller:
var myMap= component.get("v.IndexMap"); alert(myMap.length);
The above code result to "undefined". Actually I have to get "5" as myMap has 5 elements. Can you please help in getting this.
Thanks in advance.
Regards,
Naveen.
A collection that maps keys to values. A map can’t contain duplicate keys. Each key can map to at most one value. Defaults to an empty object, {}. Retrieve values by using cmp.get("v.sectionLabels")['a'].
Please try below code and let us know if it works.
Component: Controller: Hope this helps.
Mark this as solved if it;s resolved.
Regards,
Nagendra.
For getting the length of a attribute of type " Map " from Lightning Controller.
Please try below code and let us know if it works.
Component: Controller : I hope, It will help you.
Regards,
Ajay
Please mark my answer as a solution if it is helpful.