Array.prototype.lengthintermediateconst arr = []
arr.push('a') // returns 1
arr.push('b') // returns 2
arr.length // β 2length updates automatically β check it after mutations to know the current array size.
Every time you push an element onto an array, length increases by the number of elements pushed. Knowing the resulting length without having to recount is useful in tight loops.
Challenge: Implement lengthAfterPush(arr, ...vals) that pushes all vals into arr and returns the new arr.length.
lengthAfterPush([1, 2], 3, 4) // β 4
lengthAfterPush([], 10) // β 1