# Array elements order

**URL:** <https://forum.inductiveautomation.com/t/array-elements-order/77740>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [August 11, 2023, 7:41am UTC](https://forum.inductiveautomation.com/t/array-elements-order/77740 "2023-08-11T07:41:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![g.cascales](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@g.cascales](https://forum.inductiveautomation.com/u/g.cascales)\
**Post date:** [August 11, 2023, 7:41am UTC](https://forum.inductiveautomation.com/t/array-elements-order/77740/1 "2023-08-11T07:41:35Z")

</div>

Hello there,

why is this array (SerialNumbers) losing the order of the elements?

I marked my guess in red.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/9/c9f6890b4097b9b254b3454a78caa99080398460.png)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 11, 2023, 12:40pm UTC](https://forum.inductiveautomation.com/t/array-elements-order/77740/2 "2023-08-11T12:40:18Z")

</div>

Because you are using `.pop()`, which alters the array and changes the meaning of following indices.

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.inductiveautomation.com/u/user66)\
**Post date:** [August 11, 2023, 1:02pm UTC](https://forum.inductiveautomation.com/t/array-elements-order/77740/3 "2023-08-11T13:02:01Z")

</div>

In line 55 `newArray = serialNumber`  
This just taking the reference of serialNumber i.e. any changes that is made in newArray will reflect in serialNumber.

What you need to do is to take copy of serialNumber to newArray instead of equating it.

try `newArray = serialNumber[:]` or `newArray = serialNumber.copy()`

I don't exactly know how to take a copy in Jython.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 11, 2023, 1:37pm UTC](https://forum.inductiveautomation.com/t/array-elements-order/77740/4 "2023-08-11T13:37:54Z")

</div>

Since this is a native Java array of simple strings, an easy shallow copy would just be `list(serialNumbers)`. The slice syntax may work as well, but might be less explicit for a Python newcomer.
