Home > Web Front-end > JS Tutorial > Advanced JavaScript (10) Array Array Detailed Explanation

Advanced JavaScript (10) Array Array Detailed Explanation

黄舟
Release: 2017-02-11 14:59:44
Original
1672 people have browsed it

JS array Detailed explanation of array

#Declaration method of array

##arrayObj = new Array();

//Create an array.

var arr1 = new Array();

arrayObj = new Array([size])

//Create an array and specify the length. Note that it is not the upper limit, but the length.

var a = new Array(5);

arrayObj = new Array([element0], [element1], ..., [elementN])

//Create an array and assign values.

var a = new Array(["b", 2, "a", 4,]);

arrayObj = [element0 , element1, ..., elementN]

//Abbreviation for creating an array and assigning values. Note that the square brackets here do not mean that they can be omitted.

var a = ["b", 2, "a", 4,];

Note: Pay attention to the " The difference between []” and without “[]

var a = new Array(5); // refers to creating an array with a length of 5

var a = new Array([5]); // refers to creating an array with a length of 1, and the first digit is 5

Array operation (passing address)

##

var t2=new Array();
t2[0]=1;
t2[1]=2;
test2(t2); //传地址(数组)
function test2(var2) {
for(var i=0;i<var2.length;i++) {
var2[i]=var2[i]+1;
}
}
for(var i=0;i<t2.length;i++) {
alert(t2[i]); }
Copy after login

The above is JavaScript advanced (10) Array Array Array detailed explanation, for more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!

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