# Maps

A `Map` is a new object type in ES6 that represents a data structure to hold a collection of `key-value` pairs. A key in Map can be of any type - any primitive type, symbol, date, object or a function can be a key. Same holds for the values.

## Create Map

```javascript
// create map
let coolDude = new Map();

// set key-value pairs for the map
coolDude.set('wears', ['Red Shirt', 'Green Pant', 'Sunglasses (even in night)']);
coolDude.set('drives', 'Red Mustang');

// you can chain the set
coolDude.set('drinks', '7-up')
        .set('speak', (words: string) => `Yo!Wazzup!${words}`;
```

### Initialize Map with an array:

The following JSFiddle creates a Map of few commonly needed regular expression , like for phone number or email address, initialized with an array. The react component uses this map to validate values entered in email or phone fields.

[JSFiddle Example](https://jsfiddle.net/tiwarib/uh9yL1um/#tabs=result,js,html,css)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bharat-tiwari.gitbook.io/our-tech-journal/es6/maps.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
