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: 
Komag
Roku Guru

roAssociativeArray Appen() doesn't append nested roAssociativeArrays!

I've discovered, to my dismay, that when you append one AA (roAssociativeArray) to another one, if it finds any same keys it will REPLACE it! Yes, I know that's exactly what it says it will do, so good for it for being literal, but I just figured if it found a nested AA it would nicely Append() it, rather than replace it.

This is what I want, or maybe a different but similar command, such as NestAppend() or something.

As it is, I have to manually deal with this, and for now, thankfully only one layer, so I can go through each key/value in the top AA and Append() each of those one at a time, with a big FOR EACH loop.
0 Kudos
2 REPLIES 2
RokuNB
Roku Guru

Re: roAssociativeArray Appen() doesn't append nested roAssociativeArrays!

The name ".append()" is an unfortunate misnomer. Method should have been named ".update()", because that's what it does: A.append(B) adds (if new) to A - or replaces (if pre-existing) - key-value pairs from B. It is a shorter (and faster) version of:
for each key in B 
A[key] = B[key]
next
0 Kudos
Komag
Roku Guru

Re: roAssociativeArray Appen() doesn't append nested roAssociativeArrays!

Yeah, that makes it more clear.
0 Kudos