【发布时间】:2023-03-18 16:14:01
【问题描述】:
基本上,我试图复制此页面上的第一个答案 (Sorting object properties based on value),并将我的对象排序到一个数组中。但我收到此错误消息:
TypeError: 无法将 undefined 或 null 转换为对象
怎么了?
const denom = {
'ONE HUNDRED': 100.00,
'TWENTY' : 20.00,
'TEN' : 10.00,
'FIVE': 5.00,
'ONE' : 1.00,
'QUARTER': 0.25,
'DIME': 0.10,
'NICKEL': 0.05,
'PENNY': 0.01
};
const denomSorted = Object.keys(denom[0]).sort((a, b) => denom[0][b] - denom[0][a]);
denomSorted.forEach(x => console.log(x + ': ' + denom[0][x]));
【问题讨论】:
-
denom[0] => denom
标签: javascript