Skip to content
Advertisement

How can i add fields inside empty array?

Good morning guys

I have to create a new JSON object array using the user array but when I do this getting the below error. could someone help me here? or help me to understand the mistake?

JavaScript

enter image description here

Expected Result:

all user should be like this

JavaScript

Advertisement

Answer

Your test function can be fixed in the following manner:

JavaScript

However the above looks over complicated, and a map call would simplify things a lot.

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