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

后端 未结 3 2009
迷失自我
迷失自我 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 01:02

    Is there a problem doing

    [data.statuses].concat(allStatuses);
    

    If you are using ES6, you can do

    var newStatuses = [data.statuses, ...allStatuses]
    

提交回复
热议问题