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
Surender reddy SalukutiSurender reddy Salukuti 

how can i separate value from key value pair in Map salesforce lightning ?

Hi i have a one requirement i need to saparate values in a map i am geeting id and value in salesforce lightning 
'{"0053i00000213MhAAI":"Sarah Orosco","0053i00000215NfAAI":"Diana Chavez","0053i00000218YZAAY":"Shannon Fortner","0053i0000021AQ6AAM":"Sharon Snyder","0053i00000215HJAAY":"Diana Karch"}'

getting output like above i need to store names in one list how can i do that in salesforce lightning aura component .
below is my code 
doInit: function(component, event, helper) {
        // Create the action
        let action = component.get("c.retrieveAgentDMName");
        // Add callback behavior for when response is received
        action.setCallback(this, function(response) {
            let state = response.getState();
            console.log('response.getState()'+state);
            if (state === "SUCCESS") {
                console.log("Success" +response.getReturnValue());
                 console.log("stringify"+JSON.stringify(response.getReturnValue()));
                component.set("v.agentsNameWrapper", response.getReturnValue());
                component.set("v.agentsNames", JSON.stringify(response.getReturnValue().useridToNames));
                             
            }

please help me on this .

Thank you ,
Surender Reddy 

CharuDuttCharuDutt
Hii Surrender
You Can Refference Below Code
public class IterateController {
@AuraEnabled
public static Map < String, String > fetchMapvalues() {
Map < String, String > MapTest = new Map < String, String >();
MapTest.put(‘Test1’, ‘Jaya’);
MapTest.put(‘Test2’, ‘Krishna’);
MapTest.put(‘Test3’, ‘WordPress’);
MapTest.put(‘Test4’, ‘Com’);
system.debug(MapTest);
return MapTest;
}
}



<aura:component implements=”force:appHostable,flexipage:availableForAllPageTypes” access=”global” controller=”IterateController”>
<ui:button label=”Fetch” press=”{!c.fetch}”/>
<br/><br/>
<aura:attribute name=”ShowTest” type=”Boolean” default=”false”/>
<aura:attribute name=”customers” type=”List” />
<aura:renderIf isTrue=”{!v.ShowTest}”>
<aura:iteration items=”{!v.customers}” var=”cus” indexVar=”key”>
{!cus.key} – {!cus.value}<br/><br/>
</aura:iteration>
</aura:renderIf>
</aura:component>



({
fetch : function(component, event, helper) {
var custNo = component.get(“v.custNo”);
var action = component.get(“c.fetchMapvalues”);
action.setCallback(this, function(response) {
var state = response.getState();
if (state === “SUCCESS”) {
var custs = [];
var conts = response.getReturnValue();
for ( var key in conts ) {
custs.push({value:conts[key], key:key});
}
component.set(“v.customers”, custs);
component.set(“v.ShowTest”, true);
}
});
$A.enqueueAction(action);
}
})
Please Mark It As best Answer If It Helps
Thank You!

 
Suraj Tripathi 47Suraj Tripathi 47
Hi Surender,

please take the referrence from below links:

https://sfdcmonkey.com/2016/11/16/how-to-use-map-in-lightning-component/
https://jayakrishnasfdc.wordpress.com/2018/09/15/iterate-map-values-in-salesforce-lightning-component/



If you find your Solution then mark this as the best answer.

Thank you!
Regards,
Suraj Tripathi