I have the following array:
packages Array (@24ff99c1)
[99767] Array (@24ff9809)
forceUpload false
length 0
name "testdocument.indd"
packageId "99767"
progressStatus "allowed"
singleItemSize 50582294 [0x303d316]
singleItemUploadedSoFar 17296352 [0x107ebe0]
sortIndex 1338984578952 [0x137c1b33f88]
status "upload busy"
totalSize 431203849 [0x19b3a609]
uploadedAtm "37015918"
uploadedSoFar "19719566"
[94854] Array (@24ff7fd9)
forceUpload false
length 0
name "testdocument.indd"
packageId "16842"
progressStatus "allowed"
singleItemSize 6344704 [0x60d000]
singleItemUploadedSoFar 6344704 [0x60d000]
sortIndex 1338984606428 [0x137c1b3aadc]
status "upload busy"
totalSize 862407698 [0x33674c12]
uploadedAtm "6344704"
uploadedSoFar ""
length 2
Now i want to sort it according to the sortIndex.I tried this like that:
packageData.data.packages.sortOn("sortIndex");
It is sorted but the problem is that my indexes get changed to 0, 1, 2, … like the following:
packages Array (@24ff99c1)
[0] Array (@24ff9809)
forceUpload false
length 0
name "testdocument.indd"
packageId "99767"
progressStatus "allowed"
singleItemSize 50582294 [0x303d316]
singleItemUploadedSoFar 17296352 [0x107ebe0]
sortIndex 1338984578952 [0x137c1b33f88]
status "upload busy"
totalSize 431203849 [0x19b3a609]
uploadedAtm "37015918"
uploadedSoFar "19719566"
[1] Array (@24ff7fd9)
forceUpload false
length 0
name "testdocument.indd"
packageId "16842"
progressStatus "allowed"
singleItemSize 6344704 [0x60d000]
singleItemUploadedSoFar 6344704 [0x60d000]
sortIndex 1338984606428 [0x137c1b3aadc]
status "upload busy"
totalSize 862407698 [0x33674c12]
uploadedAtm "6344704"
uploadedSoFar ""
length 2
How can is sort the array without losing the indexes?
Any help would be appreciated.
The issue here is your array keys are ints.
Because they are int it is acting as a regular array and not an associative array.
When you do packages[99767] you are looking at the element at index 99767.
By sorting the array it will begin your index’s at 0.
What you need to change is the keys convert them to strings.