the purpose of an array object is to use a separate variable name to store a series of values.
create an array, assign a value to it:
var mycars = new Array();
mycars = "Saab";
mycars = "Volvo";
mycars = "BMW";
you can find more examples at the bottom of the page.
What is an array?
An array object is a single variable name that is used to store a series of values.
If you have a set of data (e.g. car name), there are separate variables as follows:
However, if you want to find out a certain car from it? and not 3, but 300? it will not be an easy task!
The best way to do this is to use arrays.
Arrays can store all values with one variable name, and any one value can be accessed with a variable name.
Each element in the array has its own ID so that it can be easily accessed.
Create an array
There are three ways to create an array.
The following code defines an array object named myCars:
1: Conventional method:
var myCars=new Array();
2: Concise way:
var myCars=new Array("Saab","Volvo","BMW");
Access the array
by specifying an array name and an index number, you can access a specific element.
The following example can access the first value of the myCars array:
The following example modifies the first element of the array myCars:
| is the first element of the array.  is the second element of the array.|
You can have different objects in an array
therefore, you can have different variable types in the array.
you can include object elements, functions, arrays in an array:
Array methods and properties
use array objects to predefine properties and methods:
var x=myCars.length // the number of elements in myCars
var y=myCars.indexOf("Volvo") // The index value of the "Volvo" value
Complete array object references
You can refer to the complete reference manual for all the properties and methods of arrays on this site.
The reference manual contains descriptions of all properties and methods (more examples).
Complete array object reference manual
Create a new method
Example: create a new method
The above example creates a new array method for converting array lowercase characters to uppercase characters.
Merging two arrays - concat()
Merge three arrays - concat()
Compose a string with the elements of an array - join()
Delete the last element of the array - pop()
Add a new element at the end of the array - push()
Reverses the order of the elements in an array - reverse()
Delete the first element of the array - shift()
Select elements from an array - slice()
Array sort (in ascending alphabetical order) - sort()
Sort numbers (in ascending numeric order) - sort()
Sort numbers (in descending numerical order) - sort()
Add an element at position 2 of the array - splice()
Convert array to string - toString()
Add a new element at the beginning of the array - unshift()