Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 

roAssociative Array

Hi,

Is there any way we can avoid roAssociative Array default sorting behavior using the key

for ex {
b: "test",
a : "test1",
c : "test3"
}

it auto sorts to a,b,c.

Thanks in advance for the help.

Prajwal
0 Kudos
2 Replies
Highlighted
Komag
Level 9

Re: roAssociative Array

I don't think so, but you're not supposed to rely on AA sorting order anyway. To really have the sort order to be reliable, I would just use a standard array.
0 Kudos
Roku Employee
Roku Employee

Re: roAssociative Array

"prajwalshetty" wrote:
Hi,

Is there any way we can avoid roAssociative Array default sorting behavior using the key

for ex {
b: "test",
a : "test1",
c : "test3"
}

it auto sorts to a,b,c.

Thanks in advance for the help.

Prajwal


As Komag said, you shouldn't rely on the order of enumeration on an associative array.

http://sdkdocs.roku.com/display/sdkdoc/ ... r=expTOexp[STEPexp]/ENDFOR
Objects that have no intrinsic order (like AssociativeArray) are enumerated in apparent random order


In the current implementation, the enumeration order depends on a combination of key hashes and order of item creation.
It's unlikely to be in alphabetical sorted order for any non-trivial and non-contrived example.

I don't think your example of b,a,c would enumerate as a,b,c even, so I wonder if there is more to your use case than the example?

But again as Komag said, if you care about preserving arbitrary item order than using an ordered type such roArray or roList might serve better.
0 Kudos