My question is if I use an array like this,
var arr1 = [1, 2, 3, 4];
console.log(arr1.length); // 4 (Expected)
If I update the length property, the array gets updated too.
arr1.length = 0;
console.log(arr1); // []
I'd like to know how this is being done (the internals)?
Also, I'm not sure if getter and setter methods of the property length
(that are ways to run a function if the property gets accessed or set) are used here. I think they're not.
If it's being used, length
should not be visible directly when I expand the array in the browser console. But we get the length
directly without running any functions.
The console when I use get/set for a property of an object,
Getting the value of length
property directly without running any functions,