The following small series will introduce the definition and use of js multi-dimensional arrays and hash arrays. I think this is quite good. Now I will share it with you and give you a reference. Let's take a look at the multi-dimensional array definition.
Define an 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 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 [row] [column];
For example:
Arr [0] [0] //
Arr [1] [0] // d
Hash array Definition
The associated array in JavaScript is more convenient in array search because the associated array has an index of the key value. It also makes the implementation of the corresponding code algorithm clearer and easier to read and maintain.
var myhash = new Array();
Add a key value to the Hash join Array
myhash['new'] = 'newval'; myhash['new2'] = 'newval_2';
Access the Hash associated array
Myhash ['new']; // access with the key name
Delete the existing key value of the Hash array delete myhash ['new'];
Traverse Hash Array
For (key in myhash) {console. log (key); // key obtains the key name myhash [key]; // gets the value}
Common js Array Operations
ToString (): converts an array into a string.
ToLocaleString (): converts an array into a string.
Join (): converts an array into a string connected with symbols.
Shift (): removes an element from the array header.
Unshift (): insert an element in the header of the array.
Pop (): deletes 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 (): sorts arrays in reverse order.
Sort (): sorts arrays.
Splice (): insert, delete, or replace an array element.
The definition and use of js multi-dimensional arrays and hash arrays are all the content shared by the editor. I hope to give you a reference and support for PHP.
For more information about how to define and use js multi-dimensional arrays and hash arrays, see the PHP Chinese website!