Question: Javascript is a neat language, but seems to lack some very basic facilities like maps and sets.

A **Map** is a key/value store where the keys and values can be arbitrary objects, and there is at most one value for each key, distinguished by strict equality.

A **Set** is the same as a map, except it has no values and you're only interested in existence, again by strict equality.

If I want to use these ADTs, the closest we have in javascript is the Object, which is almost right, but coerces all keys to string, which makes it useless for some things that real sets and maps would be used for.

Given maps, sets are trivial: `set[key] = true` instead of `set[key] = value`. Or one could implement the full set functionality (for small sets) with Arrays, Array.indexOf, and Array.splice. Adding a parallel values list would give map functionality. For larger data sets, one could implement a hash table on top of plain objects, but I imagine this would become a more serious project.

So my question is, is there a more idiomatic implementation, (or a simpler solution,) to get full Map/Set functionality out of Javascript than the above suggestions? Or does everyone just bite the bullet on this?

**EDIT** So it looks like the [es6 maps/sets spec](http://wiki.ecmascript.org/doku.php?id=harmony%3asimple_maps_and_sets) is the way to go. I'll accept an answer linking to/showing a simple and usable shim.

Answer: 
Unfortunately, there is no way to do this in Javascript.

[*Yet*](http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets "ECMAScript 6").
============================================================================================
*No, there is not.* But Javascript Objects are the closest representation to both sets and maps that you are going to get.

The following are different ways they can be used:

```
var foo = {]

// The following two are the same thing.
foo.bar = true; 
foo['bar'] = true; 

var bar = 'bar';
foo[bar] = true; // again, the same thing.

```

or

```
var foo = { bar: true }

```

They can be easily iterated:

```
for (item in foo) {
  if (foo.hasOwnProperty[item]) {
    console.log(item); // --> returns 'bar';
    console.log(foo[item]); // --> returns true;
  }
}

```

To check existence of a property:

```
if (foo[bar] !== undefined) {
  // ... it doesn't
}

// If one declares a property without any value,
foo.bar;

//It will still come out as undefined
console.log(foo.bar); // --> undefined

```