Skip to content
Advertisement

How to create JSON Object in JavaScript?

I have JSON like this :

JavaScript

I’m trying to create a JSON like this :

JavaScript

Code :

JavaScript

Suppose I don’t know how many data I have, how do I create this object in JavaScript?

Advertisement

Answer

You can use Array.reduce()

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