Skip to content
Advertisement

javascript overwrite previous element added to array

When i push into my array, it overwrite the last element added.

Here is my code:

JavaScript

The output i get :

JavaScript

The output i want :

JavaScript

Advertisement

Answer

You have to declare obj.item as an array and instead of equating values you should push them in the array

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