I want to add javascript map values to existing lightning map type variable

Map type in Component

<aura:attribute name="CheckedRecsMap" type="Map"  default="{}"/>

In js declaring a new map and adding the values and I want to add the map values to the existing component maps (CheckedRecsMap).

 var CheckedRecsMap = component.get("v.CheckedRecsMap");
 var newMap= new Map();

 component.set("v.CheckedRecsMap", newMap); //Will replace the old values 

Basically, I want to push into Old map.

CheckedRecsMap.set and CheckedRecsMap.push throws the error.

  • have you looked at the new lightning map component? I did it on trailhead and it seems pretty good. lightning:map is the component. can be found developer.salesforce.com/docs/component-library/bundle/… Not sure if it will help but thought i would share – disasterlooms Mar 4 '19 at 17:33
  • No, you misunderstood my question. I don't want lightning: map. I want to store key-value pair like apex Map – SFDC Mar 5 '19 at 12:43

You have to do this "manually":


Or, you could use an Object instead, which works out more like this:

var CheckedRecsObj = component.get("v.CheckedRecsObj");
var newMap = { arg1: 'value1', arg2: 'value2' };
Object.assign(CheckedRecsObj, newMap);
| improve this answer | |
  • Thanks @sfdcfox used object type and passed two arguments – SFDC Mar 5 '19 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.