Skip to content
Advertisement

Create Array of Objects Based on 2 Arrays

I have an array, it looks like this.

JavaScript

I have an array of objects, it looks like this.

JavaScript

I want the result to be like this, the datasets’s length should be 5 (based on date’s length).

JavaScript

I tried code by myself, but the result looks like this

JavaScript

Can anyone help me to code this?

Edit

JavaScript

Advertisement

Answer

It looks like, you do not respect the lenth of the dat array and just push the value to the datasets of the group.

To overcome this, you could take an object for getting the index of the date and for not given datasets, map date with value zero.

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