how do i sort this array in an array according to month and date?

You can use sort method

const ary = [
  ["Apr-08", 30, 0, 0],
  ["Apr-16", 26, 0, 21],
  ["Jul-08", 16.25, 9.25, 0],
  ["Feb-07", 58, 0, 0],
  ["Feb-08", 11, 0, 0],
  ["Jun-07", 4, 0, 0],
  ["Jul-07", 2.25, 0, 0]
]

const output = ary.sort((a, b) => new Date(a[0]) > new Date(b[0]) ? 1 : -1)

console.log(output)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top