Your Digital Media Has Never Looked So Good

 
bcolflesh
Topic Author
Posts: 10
Joined: Thu Nov 19, 2015 5:58 pm

AssociateArray Keys() Change Order?

Tue Nov 13, 2018 12:52 pm

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.
 
User avatar
RokuKC
Posts: 305
Joined: Wed Sep 10, 2014 10:44 am
Location: Roku HQ

Re: AssociateArray Keys() Change Order?

Tue Nov 13, 2018 2:01 pm

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.
 
bcolflesh
Topic Author
Posts: 10
Joined: Thu Nov 19, 2015 5:58 pm

Re: AssociateArray Keys() Change Order?

Tue Nov 13, 2018 2:39 pm

Gotcha, thanks.

Who is online

Users browsing this forum: No registered users and 4 guests