Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMC api v2 object order #10

Open
cyio opened this issue May 14, 2018 · 2 comments
Open

CMC api v2 object order #10

cyio opened this issue May 14, 2018 · 2 comments

Comments

@cyio
Copy link
Owner

cyio commented May 14, 2018

返回的是有顺序的对象结构,但 JS 的对象不保证顺序,可能超过一定个数就会被排序
要保证顺序,就用数组

JavaScript objects are not ordered.If you want objects in certain order, use array

@cyio
Copy link
Owner Author

cyio commented May 14, 2018

手动根据rank重新排序?

@cyio cyio changed the title CMC api v2 CMC api v2 object order May 14, 2018
@cyio
Copy link
Owner Author

cyio commented May 14, 2018

let data = {
  1: { rank: 2 },
  3: { rank: 1 },
  2: { rank: 3 },
}

let result = []
for (let i of Object.keys(data)) {
  result[data[i].rank - 1] = data[i]
}
console.log(result) // [ { rank: 1 }, { rank: 2 }, { rank: 3 } ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant