Hacker News new | past | comments | ask | show | jobs | submit login

I think this is actually the best way to zero an array in place. The other option is using foo.splice(0,foo.length)

foo = []; Will reassign the reference but other pointers can still have the array.

foo.length=1 will remove all elements but the first.




foo.splice(0) is actually sufficient. From the docs:

"If deleteCount is omitted, or if its value is greater than or equal to the number of elements after the position specified by start, then all the elements from start to the end of the array will be deleted."

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: