vue - array operations

Array operations

Modify the array elements according to the subscript: set

this.$set(this.list,0,{
    
    messsage:"11"})

Add, modify, and delete elements at the specified position according to the subscript

//在下标为的2数组元素前插入数据
this.list.splice(2,0,{
    
    mee:"11"})
//修改下标为2的数组元素
this.list.splice(2,1,{
    
    mee:"11"})
//修改下标为2和3的元素
this.list.splice(2,2,{
    
    mee:"11"})
//删除下标为2的一个元素
this.list.splice(2,1)

Remove the last one: pop

this.list.pop();

Added to the last one: push

this.list.push({
    
    messsage:"ss"});

Delete the top one: shift

this.list.shift();

Add to the first one: unshift

this.list.unshift({
    
    messsage:"ss"});

Flashback: reverse

this.list.reverse()

Guess you like

Origin blog.csdn.net/xiaozhezhe0470/article/details/108995301