Question: I'm trying to access a the apex Map named "resultsMap" with javascript, I would like to get contact last name using contact id.

```
public class AccessMapJS {
    public Map<ID, Contact> resultsMap{get;set;} 
    public String JsonMap{get;set;} 

    public AccessMapJS(){
        resultsMap = new Map<ID, Contact>([SELECT Id, LastName FROM Contact limit 3]);
        JsonMap=JSON.serialize(resultsMap); 
    }
}

```

VF page:

```
<apex:page controller="AccessMapJS" >
<script>
// Access here resultsMap: get contact last name using contact id

</script>
  {!resultsMap}
</apex:page>

```

Do you know hoe to accomplish that ?
Thanks in advantage for any advice.

Answer: 
Your controller is fine.

You can get it in via javascript if thats your preference:

```
var contactMap = JSON.parse('{!JsonMap}');
var lastname = contactMap['003....'].LastName;

```
Your page is fine, in that it will show the data being piped into it, but your controller needs a bit of work.

Controller:

```
public class ContactMapController {

private List<Contact> getContacts()
{
    return [SELECT Id, LastName FROM Contact limit 3];
}

private  Map<ID, String>  getLastNamesMap (List<Contact> contacts)
{
    Map <ID, String> result = new Map <Id, String>();
    for (Contact contact: contacts)
    {
        result.put (contact.Id, contact.LastName);
    }
    return result;
}

public  Map<ID, String> getAccessMap()
{
    List<Contact> contacts = getContacts();
    Map<ID, String> result = getLastNamesMap(contacts);
    return result;
}

```

}

I renamed the controller, separated out the required logic into separate methods and changed it to just return the information you wanted.

Here's the page:

```
<apex:page controller="ContactMapController" >
<h1>Contacts</h1>
<p>
  {!accessMap}
</p>
</apex:page>

```