Javascript-将数字转换为月份名称 [英] Javascript - convert number to month name

查看:70
本文介绍了Javascript-将数字转换为月份名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的问题,但由于某种原因我找不到答案.

I have a very simple problem but for some reason I can't find the answer for it.

label.forEach(function(value){
    months.push(value['month']);
    revenue.push(value['revenue']);
});

label是数字和收入的数组,在我的情况下是

The label is an array of numbers and revenue, in my case this is

[
{month: 9, revenue: 400}, 
{month: 11, revenue: 500},
{month: 12, revenue: 600}
]

这是javascript中的forEach循环,它将收入和月份数推入两个单独的数组中,问题是月份是一个数字(例如12),但是我希望.push()改为推一个月份名称(12月),我似乎找不到任何东西,所以我希望这里的任何人都可以帮助我.

This is a forEach loop in javascript, it pushes revenue and a month number into two seperate arrays, the problem is that the month is a number (e.g. 12) but I want the .push() to push a month name instead (December), I can't seem to find anything so I was hoping anyone here could help me out.

推荐答案

var months = [ "January", "February", "March", "April", "May", "June", 
           "July", "August", "September", "October", "November", "December" ];

var selectedMonthName = months[value['month']];

查看链接

堆栈1

这篇关于Javascript-将数字转换为月份名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆