Answers for "sort data using month in js"

2

sort date according to months in javascript

var allMonths = ['Jan','Feb','Mar', 'Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];

var month = [ "Apr","May","Jun","Oct","Nov","Dec","Jul","Aug","Sep"];

month.sort(function(a,b){
    return allMonths.indexOf(a) - allMonths.indexOf(b);
});

// returns  ["Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
Posted by: Guest on April-21-2021
0

Sort by month name javascript

var getDaysArray = function(year, month) {
  var names = [ 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' ];
  var date = new Date(year, month - 1, 1);
  var result = [];
  while (date.getMonth() == month - 1) {
    result.push(date.getDate() + "-" + names[date.getDay()]);
    date.setDate(date.getDate() + 1);
  }
  return result;
}
Posted by: Guest on June-26-2021

Code answers related to "sort data using month in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language