The definition of JavaScript arrays and the length of a group _ basics

Source: Internet
Author: User

This article provides a simple JS introductory tutorial, this is a JS array definition and array length example tutorial, if you are learning the JS array, we show you here how to define the array and increase the array and array length calculation instances.

Let's take a look at how to define an array

Copy Code code as follows:
var a = new Array ();
var b = new Array (8);
var c = new Array ("A", "second", "third");

or the direct amount of the array:
Copy Code code as follows:
var d = ["A", "second", "third"];

Next, add an element after the array

Copy Code code as follows:
var myarray = [];
Myarray[myarray.length] = ' new element ';

The length of the array

Array has only one property, that is, Length,length represents the number of memory space occupied by an array, not just the number of elements in the array, the B.length value is 8 in the array just defined

Copy Code code as follows:
<script>
var a = new Array ("A", "second", "third")
A[48] = "12"
document.write (A.length)
The result shown is 49
</script>

Let's take a look at modifying an array length instance

Copy Code code as follows:
var myarray = [1,2,3];
Myarray.length//Initial length is 3
Myarray.length = 2; Delete last Element
Myarray.length = 20//Add 18 elements to array

See more JavaScript syntax, you can focus on: JavaScript reference tutorial, JavaScript Code style guide, and also hope that many people support the cloud-Habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.