How can I use map function to have 3 arrays under datasets instead of another object called 'label'. When I try to put map function before 'label', just after 'dataset' in constructor function I am getting weird errors about having unexpected '.' dots etc.
Expected output
{
colors: blue,
datasets: [
{
label: 'car',
type: 'line',
data: '1'
},
{
label: 'bus',
type: 'line',
data: '5'
},
{
label: 'train',
type: 'line',
data: '10'
}
]
}
function Constructor(colors, label, type, data) {
this.colors = colors;
this.label = label;
this.type = type;
this.data = data;
this.mainData = {
colors: colors,
datasets: [{
label: label.map((label, i) => ({
type: type,
data: data[i]
}))
}]
}
};
var whyYouNoWork = new Constructor('blue', ['car', 'bus', 'train'], 'line', ['1', '5', '10']);
console.log(whyYouNoWork.mainData);