I need to sort an array by the nearest timestamp to the current one, but the sorting is wrong. How can this be done?
console.log(new Date(1627569000000));
console.log(new Date(1627565400000));
console.log(new Date(1627561800000));
console.log(new Date(1627572600000));
const arr = [{
from: 1627569000000
}, {
from: 1627565400000
}, {
from: 1627561800000
}, {
from: 1627572600000
}];
const now = 1627557449263;
const [res] = arr.sort(item => item.from - now);
console.log(new Date(res.from))