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: 
bcolflesh
Visitor

AssociateArray Keys() Change Order?

I saw from a forum post that .keys() could be appended in a for...each which defaults the associative array to alphabetical order. 

What if I want the results returned in the order they appear in the feed? I don't want to add another "order" key, but I can't think of another way from the minimal docs.
0 Kudos
2 REPLIES 2
RokuKC
Roku Employee
Roku Employee

Re: AssociateArray Keys() Change Order?

"bcolflesh" wrote:
I saw from a forum post that .keys() could be appended in a for...each which defaults the associative array to alphabetical order. 

What if I want the results returned in the order they appear in the feed? I don't want to add another "order" key, but I can't think of another way from the minimal docs.


Associative arrays do not preserve any ordering. The keys() member function returns a list of the keys at the time of the call. It doesn't have any effect on the associative array itself.

If you want to keep some other order, you would have to have the feed specify an array in the first place, or you could copy the object values in the associative array to an array and then sort it by your "order" key.
0 Kudos
bcolflesh
Visitor

Re: AssociateArray Keys() Change Order?

Gotcha, thanks.
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.