> 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/arr/array-like/object+arraylike.md).

# Object+arrayLike

[JS](/web/js.md) ⟩ [object](/web/js/val/obj.md) ⟩ [built-in](/web/js/val/builtin.md) ⟩ [Array](/web/js/val/builtin/arr.md) ⟩ [array-like](/web/js/val/builtin/arr/array-like.md) ⟩ Object+arrayLike

{% hint style="success" %}
extend [array-like](/web/js/val/builtin/arr/array-like.md) objects with custom methods.
{% endhint %}

{% tabs %}
{% tab title="⬇️ 應用" %}

* [TouchList+ext](/web/browser/event/type/touch/touchlist+ext.md) - TouchList is an [array-like](/web/js/val/builtin/arr/array-like.md).
  {% endtab %}

{% tab title="💾 程式" %}
:floppy\_disk: replit：[Object+arrayLike](https://replit.com/@pegasusroe/ObjectarrayLike#ext/Object+arrayLike.js)

```javascript
// 2023.01.17 - 07:57 - first draft
// --------------------------------------------------

// helpers
function checkType(obj) {
    if (!('length' in obj)) {
        throw Error(`${obj} is not an "array-like" object!`)
    }
}

// ⭐️ Object + array-like
// --------------------------------------------------
// 🔹 .map()
//
Object.defineProperties(Object.prototype, {

    // 🔹 .map()
    map: {
        value: function(f) {
            checkType(this);
            const arr = [];
            for (let i = 0; i < this.length; i++) {
                arr.push(f(this[i]));
            }
            return arr;
        }
    },
    
});

// export 
// -------------------------------------------
export {};              // ES module
// module.exports = {};    // CommonJS module
```

{% endtab %}
{% endtabs %}
