> 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/element/index/element-index-is-string.md).

# element index is string❗️

[JS](/web/js.md) ⟩ [object](/web/js/val/obj.md) ⟩ [built-in](/web/js/val/builtin.md) ⟩ [Array](/web/js/val/builtin/arr.md) ⟩ [access](/web/js/val/builtin/arr/access.md) ⟩ element index ⟩ is string:exclamation:

{% hint style="warning" %}
:star: the [type](/web/js/val/type.md) of [element index](/web/js/val/builtin/arr/element/index.md) is [String](/web/js/val/prim/str.md), <mark style="color:red;">**not**</mark> [Number](/web/js/val/prim/num.md):exclamation:
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}

* replit：[array index is of type 'string'](https://replit.com/@pegasusroe/array-index-is-of-type-string#index.js)

```javascript
let obj = { };
let arr = [1,2,3];

obj["1"] = 'one';

let sum = 0;

for (let i in arr) {  // ⭐️ array index is 'string'
    log(i, typeof i)  // ❗ '0', 'string', ...
    sum += i;         // ❗ string concatenation, not number addition
}

obj["1"],    // 'one'
obj[1],      // 'one' (obj[1] converted to obj["1"])

arr[1],      // 2     (arr[1] converted to arr["1"])
arr["1"],    // 2

sum,         // ❗'0012'   (not 0+1+2 = 3)
typeof sum,  // ❗'string'
```

{% endtab %}

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

* :white\_check\_mark: <mark style="color:purple;">**element index**</mark> is <mark style="color:yellow;">**accessed**</mark> throught [bracket notation \[\]](/web/js/val/obj/prop/access/bracket-notation.md).
  {% endtab %}

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

* Guides ⟩ Arrays ⟩ [Accessing and modifying array items](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Arrays#accessing_and_modifying_array_items) ⭐️
  {% endtab %}
  {% endtabs %}
