Languages
[Edit]
EN

JavaScript - day name for specific Date

0 points
Created by:
lena
384

In this article, we would like to show you how to get day name for specific Date in JavaScript.

Quick solution:

// ONLINE-RUNNER:browser;

let days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
let today = new Date();
let dayName = days[today.getDay()];

console.log(dayName);

 

Practical example

In this example, we get the day name in three steps:

  1. Use Date.getDay() method to get the day number (0 - sunday, 1 - monday etc.),
  2. Create days array with the name for the day names at specific indexes.
  3. Use the index to get the day name from days array.
// ONLINE-RUNNER:browser;

let days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
let today = new Date();
let dayName = days[today.getDay()];

console.log(dayName);
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join