DEV Community

Discussion on: Improve Your Algorithms with this Simple Equation

 
joelnet profile image
JavaScript Joel

When an item is added to or removed from the array, the length property is updated. You can check this by running this code:

const array = [1, 2, 3];
array.length = 100;

console.log(array.length) //=> 100

length NEEDS to be a property, otherwise code like this would become exponential:

for (let i = 0; i < input.length; i++) { }