JSFiddle - React, Tailwind, and code Playground

by Sam Liew

JavaScript

// Accepts a Date object or date string that is recognized by the Date.parse() method
function getDayOfWeek(date) {
  const dayOfWeek = new Date(date).getDay();    
  return isNaN(dayOfWeek) ? null : 
    ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][dayOfWeek];
}

alert( "Today is a " + getDayOfWeek(Date.now()) + "!" );