I'm trying to sort an array of notification objects in decreasing order of severity: Error > Warning > Information.
For example:
var notificationArray = [ {
code : "103",
severity : "Error"
}, {
code : "104",
severity : "Information"
}, {
code : "109",
severity : "Error"
}, {
code : "403",
severity : "Warning"
}, {
code : "510",
severity : "Information"
}, {
code : "114",
severity : "Warning"
}, {
code : "144",
severity : "Error"
}, {
code : "413",
severity : "Warning"
} ];
What's the best way to ensure this array is always sorted by severity?
P.S. I've seen other threads on sorting arrays of objects, but they mostly focus on unicode sorting rather than comparing against a fixed value like I need. Apologies if this question is repetitive.