I Have seen quite a lot of solutions for getting the month name of a Date object in JavaScript, mostly using an array or object of month names and matching them to the value of Date.getMonth() or Date.getUTCMonth().
Here is one of the more popular examples.
Whilst this approach works fine, I am wondering if I can get the name straight from the date object itself. We already have various versions of 'toString' which all provide a month name as part of their return string.
<!DOCTYPE html>
<html>
<body>
<div id="tostring"></div>
<div id="todatestring"></div>
<div id="toutcdatestring"></div>
<script>
var a = new Date();
document.getElementById("tostring").innerHTML = a.toString();
document.getElementById("todatestring").innerHTML = a.toDateString();
document.getElementById("toutcdatestring").innerHTML = a.toUTCString();
</script>
</body>
</html>
So why cant we get the month name straight from a date object, or at least get access to what ever mechanism date has for mapping names to months?