Setting it almost seems like an antipattern, because you'd expect it to be a read-only property, but it also looks to be the cleanest way to empty an array in-place (the splice version is even less intuitive).
I guess this would be one example where a comment explaining "what" (rather than "why" or "how") would be useful.
Whoah, I never knew
Array#length
was settable!Setting it almost seems like an antipattern, because you'd expect it to be a read-only property, but it also looks to be the cleanest way to empty an array in-place (the
splice
version is even less intuitive).I guess this would be one example where a comment explaining "what" (rather than "why" or "how") would be useful.
Noted. I'll add the comment. It can be confusing.