Single integer as key in firebase (Firebase array behavior) -


if insert data node/a/0 in firebase.

the result treat a array a[0].

the same way, if set data in node/a/1 first array become null

      "a" : [ null, {         "-j-22j_mb59l0ws0h9xc" : {           "name" : "chok wee ching"         }       } ] 

but fine if node/a/2

      "a" : {         "2" : {           "-j-25xjexuqcpsc-5loe" : {             "name" : "chok wee ching"           }         }       } 

my guess, firebase automatically treat single 0 , 1 array. how can prevent this?

firebase has no native support arrays. if store array, gets stored "object" integers key names.

however, people storing arrays in firebase, when call .val() or use rest api read data firebase, if data looks array, firebase render array.

in particular, if of keys integers, , more half of keys between 0 , maximum key in object have non-empty values, firebase render array. it's latter part of heuristic running into. second example sets value 2, not 0 , 1, less half of keys have values, , therefore firebase renders object.

you can't change or prevent behavior (though it's common source of confusion we'll make tweaks here in future). it's easy deal behavior once understand it. if need further help, perhaps can expand question explain need accomplish , how behavior preventing it.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -