Home >Web Front-end >JS Tutorial >A small example of js using the array length attribute to clear and truncate an array_javascript skills

A small example of js using the array length attribute to clear and truncate an array_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:03:421435browse

1. Use length to clear the array:

Copy code The code is as follows:

< script>
var arr1 = ['aaa','bbbb','http://www.jb51.net'];
alert(arr1);
arr1.length = 0;
alert(arr1); //The array is empty

2. Use length to truncate the array:

Copy code The code is as follows:

< ;script>
var arr1 = ['aaa','bbbb','c','d','e'];
arr1.length = 3;
alert(arr1); // Truncate array aaa,bbbb,c

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn