Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* @param {array} array
* @param {string} attribute
* @param {array} sortOrder
function customArraySort (array, attribute, sortOrder) {
let ordering = {}
for (let i = 0; i < sortOrder.length; i++) {
ordering[sortOrder[i]] = i
array.sort( function(a, b) {
return (ordering[a[attribute]] - ordering[b[attribute]]) || a[attribute].localeCompare(b[attribute])
return array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.