私は、それが持っている投票に基づいてソートしたいオブジェクトを持っていて、新しい/ソートされたオブジェクトにマップします。 ###キーと、それが持っている票の量に基づいてフィルタリングすること -ソート済みネストされたオブジェクトの値に基づいてオブジェクト化されます
const data = {
"comment-1508872637211" : {
"description" : "Blah",
"votes" : 1
},
"comment-1508872675949" : {
"description" : "Question",
"votes" : 11
},
"comment-1508898578089" : {
"description" : "whatever\n",
"votes" : 5
},
"comment-1508898637092" : {
"description" : "new",
"votes" : 15
},
"comment-1508900306998" : {
"description" : "baj",
"votes" : 0
}
}
console.log(data);
const sortedOnVotes = Object.entries(data);
console.log(sortedOnVotes);
// This is the part I'm getting hung up on
const newDataObject = sortedOnVotes.map(([key, value]) => value).sort();
console.log(newDataObject)
最終的に私はまだコメントを保持するには、この新しいオブジェクトのために大好きです。たとえばnewDataObjectは、このような何かを返す必要があります:
const newDataObject = {
"comment-1508900306998" : {
"description" : "baj",
"votes" : 0
},
"comment-1508872637211" : {
"description" : "Blah",
"votes" : 1
},
"comment-1508898578089" : {
"description" : "whatever\n",
"votes" : 5
},
"comment-1508872675949" : {
"description" : "Question",
"votes" : 11
}
"comment-1508898637092" : {
"description" : "new",
"votes" : 15
}
}
私はObject.values
またはObject.entries
を使用して正しい軌道に乗ってんだけど、私は本当にそれをハングアップなっていると思います。
本当にありがとうございます、ありがとうございます!
https://codepen.io/MathiasaurusRex/pen/RLzYVV
below-よう
sort()
関数を用いて配列をソートするロジックを記述しますが – brk使用 'lodashをソートする必要がある場合は、アレイに移動することができます/ sort'、使いやすく、構成が簡単です。ここで[lodash](https://lodash.com/)を参照してください。 – Umesh