如何舍入对象内部的数字

Adr*_*rin 3 javascript object rounding

如何在对象内部舍入数字,如下所示:

{1: {x:10.76, y:50.44}, 2:{x:5.887, y:23.433}, ...}
Run Code Online (Sandbox Code Playgroud)

我尝试使用地图这样做,但我猜地图只适用于数组

obj.map(function(each_element){
    return Number(each_element.toFixed(0.1));
});
Run Code Online (Sandbox Code Playgroud)

Cer*_*nce 7

使用Object.values让每个内部对象,然后遍历每个entries和新的圆滑号分配给内部对象的相应的键:

const input = {1: {x:10.76, y:50.44}, 2:{x:5.887, y:23.433} };
Object.values(input).forEach((inner) => {
  Object.entries(inner).forEach(([key, val]) => {
    inner[key] = Math.round(val);
  });
});
console.log(input);
Run Code Online (Sandbox Code Playgroud)