I have an array of objects of products, I'm trying to sort them on the price (Low to High) and (High to Low) and then map through the sorted array to display the product.
And I can sort it by the time to which in here referred to it by created
means the time the product has been created And updated
means the last time the product got modified.
- the JSX in the
map
because I'm using reactjs.
const products = [
{name: "keyboard",
id: "1",
created: 1614,
updated: 1620,
price: {
raw: 1,
formatted: "1.00",
}
},
{name: "shoes",
id: "2",
created: 1655,
updated: 1660,
price: {
raw: 2,
formatted: "2.00",
}
},
{name: "keyboard",
id: "1",
created: 1670,
updated: 1670,
price: {
raw: 1,
formatted: "1.00",
}
}
]
const sortedProducts = //products after been sorted
return(
sortedProducts.map(product =>
<div key={product.id}>
<h1>{product.name}</h1>
<h2>{product.price.formatted}</h2>
</div>
))