# accessing elements

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [object](https://lochiwei.gitbook.io/web/js/val/obj) ⟩ [built-in](https://lochiwei.gitbook.io/web/js/val/builtin) ⟩ [Array](https://lochiwei.gitbook.io/web/js/val/builtin/arr) ⟩ accessing arrays

{% hint style="success" %}

```javascript
arr.push(value)    // append element
arr.pop()          // removes and returns last element
arr.unshift(value) // prepend element
arr.shift()        // removes and returns first element

delete a[1]        // delete element

//                             ┌────────┐ <--- elements to add
arr.splice(index, deleteCount, v1, v2, v3)
//           └── start index to delete/insert elements
```

{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="info" %}
**array** [**elements**](https://lochiwei.gitbook.io/web/js/val/builtin/arr/element) can be <mark style="color:yellow;">**deleted**</mark> with the [**delete**](https://lochiwei.gitbook.io/web/js/val/obj/prop/create/delete) operator.
{% endhint %}
{% endtab %}

{% tab title="🔴 主題" %}

* [index](https://lochiwei.gitbook.io/web/js/val/builtin/arr/element/index "mention")
* [element](https://lochiwei.gitbook.io/web/js/val/builtin/arr/element "mention")
* [obj-prop](https://lochiwei.gitbook.io/web/js/val/builtin/arr/obj-prop "mention")
  {% endtab %}

{% tab title="👥 相關" %}

* :white\_check\_mark: [element](https://lochiwei.gitbook.io/web/js/val/builtin/arr/element "mention")(s) are <mark style="color:yellow;">**accessed**</mark> throught [index](https://lochiwei.gitbook.io/web/js/val/builtin/arr/element/index "mention") using [bracket-notation](https://lochiwei.gitbook.io/web/js/val/obj/prop/access/bracket-notation "mention").
* an [](https://lochiwei.gitbook.io/web/js/val/builtin/arr "mention") may have its own [obj-prop](https://lochiwei.gitbook.io/web/js/val/builtin/arr/obj-prop "mention")(s):exclamation:
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] JS.info ⟩ [iterables](https://javascript.info/iterable)
* [ ] [javascript-the-definitive-guide](https://lochiwei.gitbook.io/web/master/ref/javascript-the-definitive-guide "mention") ⟩ 7.5 Adding and Deleting Array Elements
  {% endtab %}

{% tab title="📘 手冊" %}

* [Array.prototype.splice()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) - insert/delete elements.
  {% endtab %}
  {% endtabs %}
