I'm trying to sort an array of objects by property. I can't find out where I'm making mistake, but it does not sort it at all. Could you please help me . Here check my sandbox : https://codesandbox.io/s/pedantic-villani-361wh
const data = [{
key: 33049999926180,
sn: 33049999926180
},
{
key: 33050000960170,
sn: 33050000960170
},
{
key: 33050001827158,
sn: 33050001827158
},
{
key: 33050002745147,
sn: 33050002745147
},
{
key: 33052513640473,
sn: 33052513640473
}
];
const handleClick = (data) => {
let temp = data;
temp.sort((a, b) => (a.sn < b.sn ? -1 : a.sn > b.sn ? 1 : 0));
console.log(temp); // check console
};
handleClick(data)