How do I add an item to the front of a state array in React

后端 未结 3 1987
迷失自我
迷失自我 2021-01-13 00:24

I know that you can add items to the end of the array with concat but how do I unshift to add an item to the front?

Add to the end:

var         


        
3条回答
  •  一生所求
    2021-01-13 00:53

    Actually you can use .concat in this case,

    var newStatuses = [data.statuses].concat(allStatuses);
    

提交回复
热议问题