Object.keys results in an inconsistent/different ordering compared to the keys in Firebase Data

Viewed 334

New to firebase. See the pick below, firebase returns these records in random order everytime. Is this a known behavior? I have googled this so much and every post that comes up is about randomizing the order. Also, you might find that timestamp key to be weird, that's a different debate but if you have a suggestion how I can structure this data better, please advise.

Thank you!

enter image description here

enter image description here

export const getMonthlyData = async (month, user) => {
  const performanceRef = firestore.doc(`performance/${user.id}`);
  const doc = await performanceRef.get();

    if(doc.exists) {
      const docArray = Object.keys(doc.data());
      console.log("Docs>>>>>>", docArray);
   }
}
1 Answers

The Firestore SDK gives no guarantee to the order of iteration of the properties of objects. When you call Object.keys(), you're going to get an array of strings with an order that is not predetermined. If you require for them to have an order, you should sort them yourself before processing them.

Related