I know you're asking facetiously, but foo.splice(0) is pretty useful because it avoids creating a new object. Useful if you are maintaining multiple references or for memory management.
let a = [1,2,3]
let b = a
b = [] // a is still [1,2,3]
b = a
b.splice(0) // a and b are both [] now
View all comments
Show parent comment
2
u/middlebird Sep 23 '22
Why would anyone do it any other way?