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
Release: 2016-05-16 17:03:42
Original
1423 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template