So I have an array containing reviews (which I retrieve from firebase firestore). The field 'date' is string in firestore. How can I sort the reviews in descending order based on this date? I have tried this but they are in the retrieval order.
const getReviews=async()=>{
let reviewsClone=[];
const q = query(collection(db, "reviews"), where("product", "==", uniqueProductName.product));
const querySnapshot=await getDocs(q);
querySnapshot.forEach((doc)=>{
reviewsClone.push(doc.id);
})
reviewsClone.sort(function(a,b){
return new Date(a.date) - new Date(b.date);
});
setReviews(reviewsClone);
}