Skip to content

Commit 0970124

Browse files
committed
Add note to Array.length about setting length
1 parent ddb7a2f commit 0970124

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

content/JavaScript/array.jsdoc

+8-2
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,22 @@ console.log(x.length);
107107
----
108108
instance.length : Number
109109

110-
The number of items in **this**. It is 1 greater
111-
than the index of the last item.
110+
The number of items in **this**. It is 1 greater than the index of the last item.
111+
Setting **length** to a smaller number than the current **length** will remove
112+
elements from the end of the list.
112113

113114
<example>
114115
console.log([].length);
115116
console.log(['a', 'b', 'c'].length);
116117
console.log(Array(100).length);
118+
117119
var x = [];
120+
// Assigning to an index automatically adjusts length
118121
x[50] = 'foo';
119122
console.log(x.length);
123+
124+
// Set length to 0 to clear the list.
125+
x.length = 0;
120126
</example>
121127

122128
Spec:

0 commit comments

Comments
 (0)