I have a case where a javascript array may be initialized repeatedly even when it has already been re-initialized. What I mean by initialize is this:
arr = [];
In most cases the array will already be empty so no need to perform this step. Is there any cost to doing this that would justify wrapping a condition around it?
if (arr.length > 0) {
arr = [];
}
I can also set a flag to indicate the state of the array but then I would need to maintain the state of this flag.
By the way, this is in an angular application and the function that contains this may be called repeatedly during the digest cycle. I may reconsider the overall approach but I am still curious if re-initializing an array when empty is essentially free.