Skip to content

How to sort a list by the numeric element of an alpha numeric ID

Lloyd Brookes edited this page Mar 2, 2021 · 1 revision

This Wiki page is a work in progress

sortArray(arr, {
  by: 'numeric',
  computed: {
    numeric: item => {
      const matches = item.id.match(/\d+/)
      if (matches) {
        return Number(matches[0])
      } else {
        return 0
      }
    }
  }
})