对于国际象棋应用程序,我需要根据值对该对象的元素进行排序,在 javascript 中:
const Moves = {e7e5: '-42', g8f6: '-16', h7h6: '-38', c8d7: '-29'};
var Moves = {e7e5: '-42', g8f6: '-16', h7h6: '-38', c8d7: '-29'};
//Convert to array
Moves=Object.entries(Moves);
//Sort
Moves.sort((x, y)=>x[1]-y[1]);
//Convert back to an object
Moves=Object.fromEntries(sortedObject);