Skip to content
Advertisement

Create complex array from array in React

JavaScript

Thats the original array I have from backend and now I want to build something like this:

JavaScript

So the chartDatasets will be datasets and the chartLabels will be labels.. I think this is pretty easy but I don’t know how I can do it.

I’m saving the original array in state so..

Thanks

Advertisement

Answer

If you have to modify single time you can simply assign in object like this:

JavaScript

updated according to your requirement adding extra key in data set.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement