> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/builtin/map/dont-use-object-properties.md).

# Don't use object properties

{% tabs %}
{% tab title="JS" %}

```javascript
// ❌ wrong use of Map
const wrongMap = new Map();
wrongMap['key1'] = 'value1';    // add "object properties"❗️
wrongMap['key2'] = 'value2';

// ✅ correct use of Map
const dict = new Map();
dict.set('Jessie', {phone: "213-555-1234", address: "123 N 1st Ave"});
dict.set('Hilary', {phone: "617-555-4321", address: "321 S 2nd St"});

// --------------- log ---------------

[
  wrongMap,                 // {key1: 'value1', key2: 'value2'} ⭐️
  wrongMap.has('key1'),     // false❗️
  wrongMap.delete('key2'),  // false❗️ (no such key)
  '---------------------',
  
  dict,                     // {} (object Map) ⭐️
  dict.has('Jessie'),       // true
  dict.delete('Raymond'),   // false (no such key)
  dict.delete('Hilary'),    // true  (key deleted successfully)
  dict.get('Hilary'),       // undefined (no such key)
  dict.get('Jessie'),       // {phone: "213-555-1234", address: "123 N 1st Ave"}
  
  dict.size,                // 1
  
].forEach(x => log(x));

```

{% endtab %}

{% tab title="💾 程式" %}

* codepen ⟩ [Map: don't use object properties❗️](https://codepen.io/lochiwei/pen/xxLZdRw?editors=0012)
  {% endtab %}
  {% endtabs %}
