Multidimensional array definition
Defines an array object that is used to store a series of values in a separate variable name. Use the keyword new to create an array object.
One-dimensional array definition
var myarray=new Array (' A ', ' B ', ' C '); or var myarray = [];
Two-dimensional array and multidimensional array definition
JavaScript two-dimensional arrays or multidimensional arrays are modeled by one-dimensional arrays.
Method 1.
var arr= new Array ([' A ', ' B ', ' C '],[' d ', ' e ', ' f ']);
Method 2:
var arr=new Array (
new Array (), new Array (), new array ()
);
Array Access:
arr[] [column];
Such as:
ARR[0][0]//A
Arr[1][0]//d
Hash array definition
JavaScript in the associative array, associative array because of the index of key value, so in the array lookup is more convenient, but also make the corresponding code algorithm to achieve a clearer, easy to read and easy to maintain.
var myhash = new Array ();
Add a key value to a hash associative array
myhash[' new ' = ' newval ';
myhash[' new2 '] = ' newval_2 ';
accessing hash associative arrays
myhash[' new ']; You can access it by following the key name
Delete hash array already has a key value delete myhash[' new '];
Traversal Hash Array
For (key in Myhash) {
console.log (key);//key get key name
Myhash[key];//Get Value
}
Common methods for JS array operation
ToString (): Converts an array to a string
toLocaleString (): Converts an array to a string
Join (): Converts an array into a symbolic concatenated string
Shift (): Moves an element of an array's head out
Unshift (): Inserts an element in the header of an array
Pop (): Deletes an element from the tail of an array
Push (): Adds an element to the tail of the array
Concat (): Adding elements to an array
Slice (): Returns the part of an array
Reverse (): Sort the array in reverse order
Sort (): Sorting operations on array
Splice (): Inserts, deletes, or replaces an array element
The above article on the JS multidimensional array and hash array definition and use is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.