var obj = {
"10": 20.1,
"11": 16,
"12": 12.7,
"01": 0,
"02": 0,
"03": 0,
"04": 0,
"05": 0,
"06": 0,
"07": 0,
"08": 27.6,
"09": 24.3
};
Sort by key value.
伊谢尔伦2017-06-30 10:01:25
JSON
is unordered, and the browser will automatically sort according to key, so sorting is useless.
,
欧阳克2017-06-30 10:01:25
It is recommended to convert to array first, then sort, and then convert to object
欧阳克2017-06-30 10:01:25
var obj = {
'10': 20.1,
'11': 16,
'12': 12.7,
'01': 0,
'02': 0,
'03': 0,
'04': 0,
'05': 0,
'06': 0,
'07': 0,
'08': 27.6,
'09': 24.3
}
console.log(Object.keys(obj).sort().reduce((a, b) => (a[b] = obj[b], a), {}))
扔个三星炸死你2017-06-30 10:01:25
var arr = []
for (const key in obj) {
arr[key] = obj[key]
}
This can achieve your needs
If the middle is not continuous, you need to filter it again later
阿神2017-06-30 10:01:25
Why do objects need to be sorted? Can’t we get the setting value directly through the key value?