Forum Discussion

bcolflesh's avatar
bcolflesh
Visitor
7 years ago

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.

2 Replies

  • RokuKC's avatar
    RokuKC
    Roku Employee
    "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.