Reputation: 2422
I'm doing a simple push of some data in an array using a for loop that looks like this
for(let i=0; i<dataArray.length-1; i+=2){
ref.child('data').update({[dataArray[i]]: dataArray[i+1]});
}
Looking at my data after completion, it appears that it has been uploaded in alphabetical order by key. Is this a feature of the update() function? Is there a way to get it to stay in the order of the array (AKA the order in which it is sent)?
Upvotes: 0
Views: 227
Reputation: 599001
Firebase keys are shown in alphabetical/lexicographical order by the Firebase Database console. There is no way to change this.
If you want to add them in the order they are in the array, I recommend calling push()
for each item. This generates a unique key (called a push ID) for each item, and those keys are order. While push IDs are not as easy to scan as array indices, they have many advantages in a realtime, multi-user, possibly offline system, such as Firebase.
Upvotes: 1