<p>If you run <code>mySortedArray</code> through the <a href="https://craftcms.com/docs/3.x/dev/filters.html#values" rel="nofollow noreferrer"><code>| values</code> filter</a>, it will reset the keys:</p>
<pre><code>{% set mySortedArray = myArray | supersort | values %}
</code></pre>
<pre><code>mySortedArray = array(6) {
    [0]=int(1)
    [1]=int(2)
    [2]=int(3)
    [3]=int(5)
    [4]=int(7)
    [5]=int(9)
}
</code></pre>

CC BY-SA 4.0
2020-09-04T05:51:49.430Z
Gee, I had scrutinised all the Twig filters but forgotten about Craft's! Thank you for the reminder.
Crafty Cat
CC BY-SA 4.0
2020-09-04T04:03:48.223Z
2020-09-04T04:03:48.223Z
Jalen Davenport
<p>Further to Jalen's answer, if you want to preserve your array keys, you can use this:</p>
<pre><code>{% set sortedArrayKeys = mySortedArray | keys %}
</code></pre>
<p>and then access any item with</p>
<pre><code>mySortedArray[sortedArrayKeys[index]]
</code></pre>

CC BY-SA 4.0
2020-09-04T09:36:32.230Z
2020-09-04T09:36:32.230Z
Crafty Cat
<p>Let's say we have this setup:</p>
<pre><code>{% set myArray = [9,3,5,7,2,1] %}
{% set mySortedArray = myArray | supersort() %}
</code></pre>
<p>It gives us:</p>
<pre><code>myArray = array(6) {
    [0]=int(9)
    [1]=int(3)
    [2]=int(5)
    [3]=int(7)
    [4]=int(2)
    [5]=int(1)
}

mySortedArray = array(6) {
    [5]=int(1)
    [4]=int(2)
    [1]=int(3)
    [2]=int(5)
    [3]=int(7)
    [0]=int(9)
}
</code></pre>
<p>How can I access say the second element of <code>mySortedArray</code>?</p>
<p>If I do <code>{{ mySortedArray[2] }}</code> I get <code>5</code>, but I want the <code>3</code>.</p>

<array><plugin-supersort>
How do I access a specific element of a supersorted array?
# How do I access a specific element of a supersorted array?

(Asked by: username_0 on 2020-09-04)

Let's say we have this setup:
{% set myArray = [9,3,5,7,2,1] %}
{% set mySortedArray = myArray | supersort() %}

It gives us:
myArray = array(6) {
    [0]=int(9)
    [1]=int(3)
    [2]=int(5)
    [3]=int(7)
    [4]=int(2)
    [5]=int(1)
}

mySortedArray = array(6) {
    [5]=int(1)
    [4]=int(2)
    [1]=int(3)
    [2]=int(5)
    [3]=int(7)
    [0]=int(9)
}

How can I access say the second element of mySortedArray?
If I do {{ mySortedArray[2] }} I get 5, but I want the 3.

**Tags:** array, plugin-supersort

---

## 2 answers

### Answer by username_1 on 2020-09-04. Score: 1 | Accepted answer

If you run mySortedArray through the | values filter, it will reset the keys:
{% set mySortedArray = myArray | supersort | values %}

mySortedArray = array(6) {
    [0]=int(1)
    [1]=int(2)
    [2]=int(3)
    [3]=int(5)
    [4]=int(7)
    [5]=int(9)
}

> **Comments:**
> **username_0**: Gee, I had scrutinised all the Twig filters but forgotten about Craft's! Thank you for the reminder.  

---

### Answer by username_0 on 2020-09-04. Score: 1

Further to Jalen's answer, if you want to preserve your array keys, you can use this:
{% set sortedArrayKeys = mySortedArray | keys %}

and then access any item with
mySortedArray[sortedArrayKeys[index]]


---

