0

I used this code and now the numbers 1-9 with zeros are last after 31. Example "28, 29, 30, 31, 01, 02,". what i want is to have it the regular way 01, 02, 03...09, 10, 11. how would i do this?

var everyDay = {};
for (im;im<=31;im++){
     t = (im < 10 ? '0' : '') + im
     everyDay[t] = (im < 10 ? '0' : '') + im;

}

2 Answers 2

1

It seems like the object properties are in lexicographical order (aa,ac,...,az). Have you tried an array instead?

var everyDay = [];
for (var im = 1; im <= 31; im++){
     everyDay.push((im < 10 ? '0' : '') + im);
}

However, it's hard to tell since you don't show how you use everyDay.

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

1 Comment

There is no telling in which way object properties are ordered. Don't build programs that rely on a particular order. stackoverflow.com/questions/280713/…
0

everyDay is a hash, which is not sorted by key. You will need to put the values in an array instead. Try this:

var days = []
for (im;im<=31;im++){
    t = (im < 10 ? '0' : '') + im
    days.push();
}

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.