If we change the length of an array it removes any numbered properties in the array that are in positions that are greater than the new length.
The array methods for deleting and adding properties in the array will move the existing entries around where necessary and will also retain and move any gaps between the properties.
If the length was equal to the amount of numbered properties and we increase the length then we convert a dense array to a sparse one. Exactly what a particular array method does can depend on whether there is actually a property corresponding to a given position in a sparse array.
The first two of these examples create arrays where only the length is set and there are no numbered entries at all.
Your code would then be unable to distinguish between the last of the above examples and the first two. It also has a number of methods for manipulating the properties some of which we will look at as a part of our examination of how the length property works.
Where the value is omitted then no property is created for that position. An array where the length is greater than the amount of numbered properties is known as a sparse array while one with the length equal to the number of numbered properties is a dense array.
Also by combining the variants of the splice method that we have already looked at we can replace existing entries or fill gaps in the array. Where it is equal we have a dense array and where it is greater we have a sparse array. In I created http: Some beginners do not even realize that length is a writable property of arrays.
In each case the value or values removed are returned by the call.
The toString() method converts an array into a String and returns the result. Note: The returned string will separate the elements in the array with commas. Browser Support. The numbers in the table specify the first browser version that fully supports the method.