1

When I try to add an Object it just automatically sorts it, which I don't want

console.log(hwidList.csgo)

hwidList.csgo[hwidList.csgo.length] = { "HWID": 3267523467, "Name": "NewUser2", "ID": 34645674573464, "Date": "04/01/2021:22:47:59" };
console.log(hwidList.csgo)

It sorts it alphabetical

It sorts it alphabetical

Help please

Edit: Thanks for the help! It's the browser / console.log which shows it sorted but it isn't.

Image of it in terminal and it's not sorted

9
  • 5
    If order matters, then an object is the wrong data structure. Consider using an Array or Map. Commented Jan 4, 2021 at 22:00
  • Objects don't really have sorting order in JS. There is consistent implementation of this amongst the JS engines but it's not defined in the standards so don't rely on it. Commented Jan 4, 2021 at 22:01
  • so you need to figure correct index of your array if order matters, if not just use push method Commented Jan 4, 2021 at 22:02
  • @Dominik The order is defined. Commented Jan 4, 2021 at 22:02
  • 1
    @Dominik relevant question for object property order it has most spec links, if not, you can find it in the spec pretty fast. Commented Jan 4, 2021 at 22:07

1 Answer 1

1

What browser are you using? For example, in Firefox, when calling console.log the result is printed alphabetically for your convenience. This issue has nothing to do with JavaScript or your code, it is the browser trying to help you in the instance you have very large objects.

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

2 Comments

First of all thank you for your quick response didn't expect that. Yes I tested it with firefox. I am not quite convinced that its the browsers fault. I tried it with chrome and microsoft edge aswell but no luck [In Chrome][1] [In Edge][2] [1]: i.sstatic.net/lbC1E.png [2]: i.sstatic.net/ohPjs.png
I can confidently assure you this is the browser trying to help you. Additionally, as other comments have stated if order matters you are using a fundamentally incorrect data structure. If you found my answer helpful and answers your question, can you please accept?

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.