const object = {
1: 1,
2: 3,
3: 3,
4: 3,
5: 0,
6: 2,
7: 1,
8: 3
}
const propsCount = 3;
.const newObj = Object.fromEntries(Object
.entries(obj)
.sort((a, b) => a[1] - b[1])
.slice(-propsCount)
);
Object
.entries(obj)
.sort((a, b) => b[1] - a[1])
.slice(propsCount)
.forEach(n => delete obj[n[0]]);