Array.prototype.lengthintermediateconst arr = [1, 2, 3]
arr.length = 5
arr // β [1, 2, 3, <2 empty items>]Assigning a larger number to length creates a sparse array with empty slots at the end.
Setting arr.length to a value larger than the current length extends the array. The new slots are empty (holes) β they exist as indices but have no assigned value.
Challenge: Implement extend(arr, n) that sets arr.length = n and returns the new length.
extend([1, 2], 5) // β 5 (arr is now [1, 2, <3 empty items>])
extend([], 3) // β 3