Home > Net >  Object gets duplicated inside array
Object gets duplicated inside array

Time:08-17

This is the result I want to achieve

dataset: [
    dataset: [
        {
            seriesname: "",
            data: [
                {
                    value: "123",
                },
                {
                    value: "123",
                },
            ]
        },
    ]
]

My problem right now is that the second dataset gets duplicated.

This is how I am setting it (val is an integer and allYears is an array of integers):

this.grphColumn.dataSource.dataset[0].dataset = this.allYears.map(el => {
    return {
        seriesname: "Planned",
        data: [{value: val}, {value: val}]
    }
});

How can I make it so the dataset doesn't get duplicated?

CodePudding user response:

You have to map the values separately, if you dont want the seriesName to be Repeated..

const yearsMap = this.allYears.map((el) => { return { value: el } });

this.grphColumn.dataSource.dataset[0].dataset = {
        seriesname: "Planned",
        data: yearsMap
    }
  • Related