use map

How to use Map in lightning Component

Lightning Component

Sharing is caring!

Prerequisites : basic understanding of Lightning Component and apex programming

  • First we create our component controller class.
  • In this apex class we have a @AuraEnabled getMyMap() method which return type is Map type.
  • In this method first we created a new map called Mymap and put value on it . (‘key’ , ‘value’) and return the map.

  • Next we create our lightning component.
  • On the component initialize we call doInit js function and set the return value in myMap aura:attribute .
  • And we can access map attribute  value in component by using this syntax -:

{! v.MapAttributeName.keyName }



map-value output image

Check Also : Iterate Map values in Salesforce Lightning Component.

Bravo!!   🙂

Sharing is caring!

(Visited 3,220 times, 9 visits today)


    • Hi Igor,

      You can try this way: component.get(“v.sectionLabels”)[‘a’];

      for(var item in mapData){
      if(item == Country){
      component.set(“v.cities”, mapData[item] );
      where mapData is the Map attribute, it iterates the all keys in map and if the key matches the key you are searching, then get the data using (mapData[item]).

Leave a Reply