I'm trying to combine two arrays in a specific format, but I cant imagine what I'm doing wrong.
This is the output result that I would like to have:
[ data: [
{value: 100, name: 'January'},
{value: 30, name: 'February'},
{value: 150, name: 'March'},
{value: 85, name: 'April'},
{value: 60, name: 'May'},
{value: 20, name: 'June'}
],
radius: '50%' ]
This is my code:
var sales = ["100", "30", "150", "85", "60", "20"];
var months = ["January", "February", "March", "April", "May", "June"];
var rad = "50%";
var combined = sales.map(function combine(dataItem, index) {
return {
data: [{"value":dataItem, "name":months[index]}],
radius: rad
};
}).filter(function removeEmpty(item) {
return item.data.length;
});
console.log(combined);