Array is an ordered collection of elements.
Syntax
var arrayName = [elem1, elem2 .... elemN];
var arrayName = new Array(size)
How to access element of an array?
By using index notation, you can access element of an array. Index starts from 0.
Syntax
arrayName[index]
arr[0] : Return the first element
arr[1] : Return 2nd element
…..
…..
arr[n] : Return n-1th element
array.html
Array
"text/javascript">
var arr = [2, "Hello", 123.5, true];
document.write("arr[0] : " + arr[0] + "
");
document.write("arr[1] : " + arr[1] + "
");
document.write("arr[2] : " + arr[2] + "
");
document.write("arr[3] : " + arr[3] + "
");
document.write("arr[4] : " + arr[4] + "
");
document.write(typeof arr);
Open above page in browser, you can able to see following data.
arr[0] : 2
arr[1] : Hello
arr[2] : 123.5
arr[3] : true
arr[4] : undefined
object
What is the maximum index number in array?
Arrays in javaScript use 32-bit indexes. So the maximum array index number is ((2^32)-2) = 4294967294 (Since arrays are zero indexed).
Previous Next Home
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here