const arr = [
{
id: 10,
name: 'Oleg'
},
{
id: 1,
name: 'Sasha'
},
{
id: 5,
name: 'Slava'
},
{
id: 2,
name: 'Nikita'
},
];
arr.sort((a, b) => b.id - a.id).map(arr => arr.name);
const [ first, second ] = [...arr]
.sort((a, b) => b.id - a.id)
.slice(0, 2)
.map(n => n.name);
const [ { name: first }, { name: second } ] = arr.reduce((acc, n) => {
if (!(acc[0].id >= n.id)) {
acc[1] = acc[0];
acc[0] = n;
} else if (!(acc[1].id >= n.id)) {
acc[1] = n;
}
return acc;
}, [ {}, {} ]);