json
1{ 2 "790133": { 3 "color": 15, 4 "index": 200, 5 "score": 247371, 6 "name": "baby grogu" 7 }, 8 "797240": { 9 "color": 12, 10 "index": 160, 11 "score": 155557, 12 "name": "awaken booster" 13 }, 14 "811597": { 15 "color": 10, 16 "index": 162, 17 "score": 160344, 18 "name": "Mobile=can't stopshootig" 19 }, 20 "814504": { 21 "color": 15, 22 "index": 162, 23 "score": 85109, 24 "name": "lqk" 25 }, 26 "814551": { 27 "color": 11, 28 "index": 91, 29 "score": 44631, 30 "name": "yazan salih" 31 }, 32 "814804": { 33 "color": 10, 34 "index": 126, 35 "score": 27276, 36 "name": "aguem16389'692555" 37 }, 38 "817505": { 39 "color": 11, 40 "index": 149, 41 "score": 27074, 42 "name": "spav" 43 }, 44 "818090": { 45 "color": 5, 46 "index": 221, 47 "score": 35063, 48 "name": "" 49 }, 50 "819851": { 51 "color": 15, 52 "index": 92, 53 "score": 48027, 54 "name": "ര" 55 }, 56 "820014": { 57 "color": 12, 58 "index": 148, 59 "score": 31940, 60 "name": "A" 61 } 62}
こういう連想配列?にJSONが入っているデータのソートを行いたいのですが、score
の値で並び替えをしたいです。
sort
では(連想配列なので)上手くいかなかったので、他の方法を教えてほしいです。
js
1json = json.sort((a, b) => { 2 return ((a.score < b.score) ? 1 : -1); 3});
求めたい結果
json
1{ 2 "790133": { 3 "color": 15, 4 "index": 200, 5 "score": 247371, 6 "name": "baby grogu" 7 }, 8 "811597": { 9 "color": 10, 10 "index": 162, 11 "score": 160344, 12 "name": "Mobile=can't stopshootig" 13 }, 14 "797240": { 15 "color": 12, 16 "index": 160, 17 "score": 155557, 18 "name": "awaken booster" 19 } 20 ... 21}
回答1件
あなたの回答
tips
プレビュー