How to prevent automatic sort of Object numeric property?

后端 未结 10 1279
醉酒成梦
醉酒成梦 2020-12-03 20:57

Why I met this problem: I tried to solve an algorithm problem and I need to return the number which appeared most of the times in an array. Like [5,4,3,2,1,1] should return

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 21:24

    I came across this same problem, and after search a lot about that, i found out that the solution to prevent this behavior is make key as string.

    Like that:

    {"a": 2, "b": 2}
    

提交回复
热议问题