The length property of an array is useful to resize or empty an array quickly. Let’s apply length property on number array to resize the number of elements from 5 to 2,
1 2 3 4 5 6 | var array = [1, 2, 3, 4, 5]; console.log(array.length); // 5 array.length = 2; console.log(array.length); // 2 console.log(array); // [1,2] |
and the array can be emptied too
1 2 3 4 | var array = [1, 2, 3, 4, 5]; array.length = 0; console.log(array.length); // 0 console.log(array); // [] |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.