Issues with indexOf and splice (resolved)

let list = [1, 2, 3]
list.splice(list.indexOf(2), 1)
// [1]
console.log(list)

and

let list = [1, 2, 3],
    idx = list.indexOf(2)
list.splice(idx, 1)
// [1, 3]
console.log(list)
What"s the difference between

?

tried several more times, but there was no difference. Maybe there was something wrong with the execution before.

Apr.11,2021
There is no difference between

. Besides, the output of the above code is also [1Jing 3]

.
Menu