JS array delete splice 区别

时间:2022-08-14 19:32:21

Delete in this case will only set the element as undefined:

> myArray =['a','b','c','d']

>delete myArray[0]

true

> myArray

[undefined,"b","c","d"]

Splice actually removes the element from the array:

> myArray =['a','b','c','d']

>myArray.s
plice(0,1)
true

> myArray

["b","c","d"]