Vue push() pop() shift() unshift() splice() sort() reverse()

参考:https://www.cnblogs.com/ifieer/p/9926533.html

data() {
    return {      
      arrayList:['1', '2', '3', '4', '5', '6', '7', '8', '9']
    };
  },
 methods: {
    init() {      
      console.log('init:', this.arrayList); //["1", "2", "3", "4", "5", "6", "7", "8", "9"]
      this.arrayList.push('10');
      console.log('push:', this.arrayList);//["1", "2", "3", "4", "5", "6", "7", "8", "9","10"]
      this.arrayList.unshift('0');
      console.log('unshift:', this.arrayList);//["0","1", "2", "3", "4", "5", "6", "7", "8", "9","10"]
      this.arrayList.pop();
      console.log('pop:', this.arrayList);//["0","1", "2", "3", "4", "5", "6", "7", "8", "9"]
      this.arrayList.shift();
      console.log('shift:', this.arrayList);//[1", "2", "3", "4", "5", "6", "7", "8", "9"]
      this.arrayList.splice(0, 1);
      console.log('splice:', this.arrayList);//["2", "3", "4", "5", "6", "7", "8", "9"]
      this.arrayList=this.arrayList.reverse();
      console.log('reverse:', this.arrayList);//["9", "8", "7", "6", "5", "4", "3", "2"]
      this.arrayList=this.arrayList.sort();
      console.log('sort:', this.arrayList);//["2", "3", "4", "5", "6", "7", "8", "9"]
      this.arrayList=this.arrayList.filter(item=>item!=='2');
      console.log('filter', this.arrayList);//["3", "4", "5", "6", "7", "8", "9"]     
    }
}

 

posted on 2019-06-28 16:43  技术高超  阅读(437)  评论(0编辑  收藏  举报