Home > Web Front-end > JS Tutorial > JS array array detailed explanation_basic knowledge

JS array array detailed explanation_basic knowledge

WBOY
Release: 2016-05-16 18:55:03
Original
1097 people have browsed it

1. Array declaration method
(1): arrayObj = new Array(); //Create an array.

Copy code The code is as follows:

var arr1 = new Array();

(2): arrayObj = new Array([size]) Create an array and specify the length. Note that it is not the upper limit, but the length.
Copy code The code is as follows:

var a = new Array(5);

(3): arrayObj = new Array([element0[, element1[, ...[, elementN]]]]) Create an array and assign values.
Copy code The code is as follows:

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

(4): arrayObj = [element0, element1, ..., elementN] is the abbreviation for creating an array and assigning values. Note that the square brackets do not indicate Can be omitted.
Copy code The code is as follows:

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

(Note): Pay attention to the difference between "[]" and without "[]"
Copy Code The code is as follows:

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

2. Common methods of arrays
3. Array operations (passing address)
Copy code The code is as follows:

var t2=new Array();
t2[0 ]=1;
t2[1]=2;
test2(t2); //Pass address (array)

function test2(var2) {
for(var i=0 ;ivar2[i]=var2[i] 1;
}
}
for(var i=0;ialert(t2[i]);
}
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