Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はこのようなオブジェクトを持っています:
{tsg2b: 1, fjdlf: 0}
次に、値に基づいてこのオブジェクトをソートする必要があります。たとえば、次のような結果が必要です。
{fjdlf: 0,tsg2b: 1}
オブジェクトをJavaスクリプトでソートできないため、オブジェクトを配列に入れてから配列をソートする必要があります。以下を試してください -
var test = {tsg2b: 1, fjdlf: 0} var sortable = []; for (var item in test) sortable.push([item, test[item]]) sortable.sort(function(a, b) {return a[1] - b[1]})