Array.prototype.splice()

splice () method is modified by deleting or replacing an existing array of elements or adding new elements in place, and returns the contents to be modified in an array. This method changes the original array.
Add 1 position on one

we do not have the subscript for the item 4 of this super, just add this one to the maximum term after

start removing elements from 0 2, insert "drum"

to start deleting from 2 0 elements, insert "drum" and "guitar"

to start deleting an element from No. 3

to start deleting an element from the first two, insert the "trumpet" but will also remove an element

begin removing two elements from No. 0, insert "parrot", "anemone" and "blue"

begin removing two elements from the first two

start deleting an element from the penultimate 2

delete all elements from the two begin

Postscript: we write vue time, often with to delete a

  deleteEle(ele) {
      for (const item of this.list1) {
        if (item.id === ele.id) {
          const index = this.list1.indexOf(item)
          this.list1.splice(index, 1)
          break
        }
      }
      if (this.isNotInList2(ele)) {
        this.list2.unshift(ele)
      }
    },

The inside is to find one that you want to delete, and then delete one, delete it won one of the rest of the array of
the above code mean if list1 remove an item, isNotList2 will increase the deleted item.

Guess you like

Origin www.cnblogs.com/smart-girl/p/11460663.html