I am trying to sort data in an array of objects. The problem is I don’t have any date property so I can’t be able to show the latest data,
I am trying to sort it like out this way but it is not working.
const filter2 = data.sort((a, b) => (a > b ? -1 : 1))
Here is my data example
const data = [
{
_id: "6221943a03931299eb8c343b",
title: "product 1",
brand: "Beats",
reg_price: "299",
sale_price: "200",
stock: "150",
},
{
_id: "6221943a03931299eb8c343b",
title: "product 2",
brand: "Beats",
reg_price: "299",
sale_price: "200",
stock: "150",
},
{
_id: "6221943a03931299eb8c343b",
title: "product 3",
brand: "Beats",
reg_price: "299",
sale_price: "200",
stock: "150",
},
{
_id: "6221943a03931299eb8c343b",
title: "product 4",
brand: "Beats",
reg_price: "299",
sale_price: "200",
stock: "150",
},
{
_id: "6221943a03931299eb8c343b",
title: "product 4",
brand: "Beats",
reg_price: "299",
sale_price: "200",
stock: "150",
},
]