I need a list in the following Format in Javascript to populate my graph:
var songs = { "Mon": 80, "Tues": 40, "Wed": 60, "Thu": 80, "Fri": 40, "Sat": 60, };
I am getting my data from my API which comes back in a list in the format of:
How can I loop through my list and adapt it to the form of the "songs" list?
Outcome:
var outputList = { "19 Jan 2021": 2, "20 Jan 2021" : 5 .... }
If I understood your problem properly the following should solve it:
let apiResponse = [ {description: '18 Jan 2021', value: 1}, {description: '19 Jan 2021', value: 2} ] let outputList = {}; apiResponse.forEach((row) => { outputList[row.description] = row.value; }); console.log(outputList);
1.4m articles
1.4m replys
5 comments
57.0k users