Move item in array to last position

后端 未结 5 1584
终归单人心
终归单人心 2021-02-02 08:11

I have an array of objects. I want to move a selected object to the last position in the array. How do I do this in javascript or jquery?

Here is some code I have:

5条回答
  •  长发绾君心
    2021-02-02 09:00

    Move any element to last position - for lodash users:

        const array = ['A', 'B', 'C', 'D'] // output: A, B, C, D
    
    // finds index of value 'B' and removes it
        _.pull(array , 'B') // output: A, C, D
    
    // adds value of 'B' to last position
        _.concat(array , 'B') // output: A, C, D, B
    

提交回复
热议问题