Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | 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 2
Komag
Roku Guru

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
RokuKC
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
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.