I am trying to sort out the array based on the specific order. The data itself will include fruits, prices, etc. I am struggling to make a sort() function to arrange the order.
fruit = ["Banana", "Orange", "Apple", "Pear"];
const data = storeData.filter(...);
// sort the data
data.sort((a, b) => (a.fruit > b.fruit ? 1 : -1)); // output: apple, banana, orange, pear
I expect the result to be banana, orange, pear, apple
instead of apple, banana, orange, pear
or banana, orange, apple, pear
. I am still learning more. Thank you!
By the way, I am using Reactjs or javascript-based platform.