array.splice() 删除条目的内容但不删除条目本身

array.splice() removes the content of an entry but not an entry itself

我正在尝试使用 array.splice() 从数组中删除一个条目,使用这段代码:

let replaceThisArrRemoved = replaceThisArr.splice(positionNumber, 1);

当我使用 replaceThisArr = ["apple", "orange", "pear"]positionNumber = 1 时,它会 return replaceThisArr = ["apple", "", pear"]

我正在努力 return replaceThisArr = ["apple", "pear"]

有没有其他方法可以做到这一点,或者我的代码有什么问题需要修复?

我在这里测试过它 returns 预期值。

[ 'apple', 'pear' ]

仔细检查您的代码中是否存在您应该修复的错误。

看看这个控制台输出-