# JavaScript All Map Concept Simplified | JavaScript Map Tutorial

Javascript map is a build in data structure of Javascript. It was introduced with Ecma Script 6 or ES6 features. Map basically stores the key value pair data init. Also map is very optimized and most of its operations are in constant time complexity. So if you are doing Data Structure and Algorithms in Javascript then map will be used a lot.

## Declare a map

`const myMap = new Map();`

## Set value in the Map

`myMap.set('key1', 'value1');`

`myMap.set('key2', 'value2');`

## Get Value with Key From Map

`const value = myMap.get('key1');`

## Traverse Through a Map

`for (const [key, value] of myMap)`

`{`

``console.log(`${key}: ${value}`);``

`}`

## Check Map Size

`const size = myMap.size;`

## Delete a Item

`myMap.delete('key1');`

## Clear All Map

`myMap.clear();`

## Check if A Key Exists

`const keyExists = myMap.has('key1');`

## Time Complexity & Space Complexities

The time complexity of set, get, has, delete are O(1). Map takes space complexity of O(1).
