function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Karthik jKarthik j 

Map.set is not working in js LWC

Hi Everyone

I am getting result as returned data from the apex method in js.
here result is the array of objects, I am iterating result over a for loop and trying to add a single object as a value and string as a key to the map ExistingRuleDataMap. but in the logs ExistingRuleDataMap is printing as empty. what I am missing here please help me.
Here is my JS code.

getExistingFilterData({
            clusterName: singleCluster
       })
       .then(result=>{
        console.log('RESULT>>'+JSON.stringify(result));
        for(let data of result){
            console.log('DATA>>'+JSON.stringify(data));
            this.ExistingRuleDataMap.set(data.Cluster__c,data);
        }
        console.log('EXISTING COLLECTION RULE DATA MAP>>'+JSON.stringify(this.ExistingRuleDataMap));
       })
       .catch(error=>{
           console.log('ERROR>>'+error);
       })


Thanks in advanse
mukesh guptamukesh gupta
Hi Karthik,


First point are you make sure you getting ressult in  console.log('DATA>>'+JSON.stringify(data));

Please use below line  :-
 
console.log('EXISTING COLLECTION RULE DATA MAP>>'+JSON.parse(JSON.stringify(this.ExistingRuleDataMap)));


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh