1

I have the below data structure in Firebase database and I would like to order keys of the 2017 branch as shown below in the screenshot. However when I get the keys the first items returned are 10, 11, 12 before 01, 02, 03, 04, 05, 06, 07, 08 ,09. The order should be as the screen shot.

My database call is

databaseRoot.ref('contractors/' + userObject.uid + '/timesheets').once('value', function(snapshot) { });

enter image description here

I also tried orderByKey() but I get the same results

1
  • I have changed my data structure to remove prefixed 0 and now all is the right order. Not the best approach but working fine. But there should be a way to order the above. Commented May 9, 2017 at 11:54

1 Answer 1

1

You were right to remove the prefixed 0. It's because Firebase Database keys are strings ordered lexicographically, and therefore it was returning them in an 'unnatural' looking order.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.