Skip to content Skip to sidebar Skip to footer

React Push Object Into Array, Always Pushed Last Array

i'm new on React Js things. already tried push object into array. I already got the result using axios, but i can't push it to array.the result always return last array, F.ex : [0

Solution 1:

You are adding tempObj to temp array on each iteration and changing value of tempObj as well.

So by reference you are updating value of each item because all items of array point to same object.

Solution 2:

Just declare var tempObj = {}; inside your map method. That will help you.

Solution 3:

Try unshift() instead push() to adds item to front of array

Post a Comment for "React Push Object Into Array, Always Pushed Last Array"