Forum Discussion

Komag's avatar
Komag
Roku Guru
7 years ago

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.
  • 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