Multidimensional array definition
Define an array array object 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 multi-dimensional array definition
JavaScript two-dimensional arrays or multi-dimensional arrays are simulated through 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[row][column];
like:
arr[0][0] // a
arr[1][0] //d
hash array definition
Associative arrays in JavaScript. Associative arrays have indexes of key values, they are more convenient in array search. At the same time, they also make the corresponding code algorithm implementation clearer, easy to read and maintain.
var myhash = new Array();
Add key value to a Hash associative array
myhash['new'] = 'newval';myhash['new2'] = 'newval_2';
Access Hash associative array
myhash['new']; // Keep up with the key name to access
Delete the Hash array already has a key value delete myhash['new'];
Iterate through the Hash array
for(key in myhash){ console.log(key); //key gets the key name myhash[key]; // Gets the value}Common methods for operating js arrays
toString(): Convert an array into a string
toLocaleString(): Convert an array into a string
join(): convert an array into a string connected with symbols
shift(): move an element in the header of the array out
unshift(): Insert an element at the head of the array
pop(): Delete an element from the end of the array
push(): Add an element to the end of the array
concat(): Add elements to the array
slice(): Returns the part of the array
reverse(): reverse sort the array in reverse
sort(): sort the array
splice(): Insert, delete or replace an array element
The above article briefly discusses the definition and use of js multi-dimensional arrays and hash arrays is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.