The importance of arrays in programming languages is self-evident, and in JavaScript, arrays are one of the most commonly used objects, arrays are ordered collections of values, and because of the weak type, the arrays in JavaScript are flexible and powerful, It's not like a Java. Strong-type advanced language arrays can hold only the same type or its subtype elements, JavaScript may hold multiple types of elements in the same array, and can be dynamically adjusted in length, which can be changed as the data increases or decreases the automatic array length.
Array () is a built-in constructor function that is used to build an array. Arrays are mainly created by the following three ways:
Array = new Array () array = new Array (
[size])
array = new Array (element0, element1, ..., ELEMENTN)
Parameters
The parameter size is the number of expected array elements. The returned array, the Length field will be set to the value of size.
Parameter element ..., ELEMENTN is the parameter list. When these parameters are used to invoke the constructor array (), the elements of the newly created array are initialized to those values. Its length field is also set to the number of parameters.
return value
Returns the newly created and initialized array.
If no arguments are used when calling the constructor array (), the returned array is empty and the length field is 0.
When the constructor is invoked, it is passed only a numeric argument, which returns an array with the specified number of elements undefined.
When other arguments call Array (), the constructor initializes the array with the value specified by the parameter.
When you call a constructor as a function, and you do not use the new operator, it behaves exactly as it did when you called it with the new operator.
Array Object method
Array Object Properties
Concat () Method:
Merging arrays
[1,2]concat ([3,4],[5,6]);//[1,2,3,4,5,6]
Join () Method:
<script type= "Text/javascript" >
var a = [1,2,3];
A.join ("");//=> "123"
</script>
Pop () Method:
Move the last element of the divisor group and return it
<script type= "Text/javascript" >
var fruits = [' apple ', ' banana ', ' pineapple '];
Fruits.pop ();//Pineapple
console.log (fruits)//["apple", "banana"]
</script>
Shift () Method:
Deletes and returns the first element of the array.
<script type= "Text/javascript" >
var a = [1,2,3];
A.shift ();//1
Console.log (a);//[2,3]
</script>
Slice (start,end)
Method: Intercepts a portion of an array without making any modifications to the original array.
<script type= "Text/javascript" >
var num = [' A ', ' B ', ' C ', ' d ', ' e '];
Console.log (Num.slice (1,4));//["B", "C", "D"]
console.log (num);//["A", "B", "C", "D", "E"]
</script>
Splice (Start,delete_count,i1,i2 ...)
Method: Deletes an array element while adding a new element. I1,i2 for the new element to be inserted
<script type= "Text/javascript" >
var arr = [' js ', ' CSS ', ' html ', ' php ', ' C '];
Arr.splice (1, 2, ' Python ', ' jquery ');//["CSS", "html"]
Console.log (arr)//["JS", "Python", "jquery" "PHP", "C"]
</script>
The above content is to introduce about JavaScript in the array () function of the list, I hope to help.