Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  25] [ 4]  / answers: 1 / hits: 36583  / 6 Years ago, thu, april 19, 2018, 12:00:00

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']);
});


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}
]


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.


More From » loops

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

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


look at the links



stack 1


[#54619] Monday, April 16, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ramseydeshaunc

Total Points: 30
Total Questions: 91
Total Answers: 103

Location: Palau
Member since Tue, May 30, 2023
1 Year ago
ramseydeshaunc questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Sun, Jul 12, 20, 00:00, 4 Years ago
Sun, Mar 29, 20, 00:00, 4 Years ago
;