I have this code
const fields = [
{ key: FORM, field: GSN, items: forms, label: 'FORM' },
{ key: STRENGTH, field: GSN, items: strengths, label: 'DOSAGE' },
{ key: QUANTITY, field: QTY, items: quantities, label: 'QUANTITY' }
]
which is being called in with:
{fields.map(({ field, key, items }) => {
const v = inputs[key]
const item = items.find(i => i[field] === v || i[key] === v)
return item ? (
<div key={key}>
{item[key]}
</div>
) : null
})}
I am looking to sort the items. The items are only numbers, but no matter where I add sort(), it throws errors. What would be best practice for sorting the output in order from lowest to highest number?