# element index is string❗️

[JS](../../../../..) ⟩ [object](../../../../obj) ⟩ [built-in](../../..) ⟩ [Array](../..) ⟩ [access](../../access) ⟩ element index ⟩ is string:exclamation:

{% hint style="warning" %}
:star: the [type](../../../../type "mention") of [](<> "mention") is [str](../../../../prim/str "mention"), <mark style="color:red;">**not**</mark> [num](../../../../prim/num "mention"):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](../../../../obj/prop/access/bracket-notation "mention").
{% 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 %}
