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

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
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
Level 7

Re: AssociateArray Keys() Change Order?

Gotcha, thanks.
0 Kudos