The concept and definition of arrays
A set of data of the same type in the general case.
In addition to the Object type, the Array type is the most common type of ECMAScript. and the array type in ECMAScript is very different from the arrays in other languages. Although arrays are ordered, each element of an array in ECMAScript can hold any type. The size of the array in the ECMAScript can also be adjusted.
How arrays are created (constructors and JSON)
The first is the new operator (constructor);
The second type is literal (JSON);
Note: Passing a value to the constructor can also create an array. If a numeric value is passed, an array containing the given number of items is created by that number, and if a parameter of another type is passed, an array of only one item that contains that value is created.
Operation of the array
Use index subscript to read the value of an array-the subscript is fixed, starting with 0
Static assignment/dynamic assignment (dynamic without specifying a size)
The length property of the array, representing the lengths
The length property of an array is not just read-only. By setting this property, you can remove an item from the end of the array or add a new item to the array.
Iterating through an array of normal for loops and for-in loops (associative arrays or objects)
Convention: All point operations can be changed to the form of brackets: Obj.name <===> Obj[name]
Detection array: Array.isarray () method
Array.isarray (): Determines whether a value in parentheses is an array
Methods of arrays
1 , push () The method can receive any number of arguments, add them to the end of the array one by one, and return the length of the modified array.
2 , pop () method removes the last item from the end of the array, reducing the array's length value, and then returns the item that was removed.
3 unshift () method
4 shift () method 1
5 , reverse () method reverses the order of the array items.
6 , sort () method arranges array items in ascending alphabetical order.
/*var a=prompt ();
var b=prompt ();
var c=prompt ();
var arr=[a,b,c];
Alert (function (A, b) {Arr.sort
return a-B;
}));
Note: If you arrange arrays in other ways rather than in alphabetical order, you must give Sort method to pass a comparison letter number (do parameters).
reverse () and
7 , Join () method converts all the elements in an array to strings and joins together, returning the last generated string. parameter is the connection symbol between the array items.
/*var arr=[1,4,1117,2,5,8,3,6,9];
//alert (Arr.join (' # '));// Convert to String
8 concat () first create a copy of the current array, then add the received parameters to the end of the copy, and finally return to the new build concat () concat () If the method is one or more arrays, the method adds each item in the array to the knot
/*alert (Arr.concat (arr1,arr2, ' hehe '));// returns the new array */
9 slice () method It can create a new array based on one or more items in the current array. &NBSP; can accept one or two Span style= "Color:rgb (255, 0, 0); > parameter, which is the start and end position of the item to be returned, excluding the end position.
Ten , Splice () method, deleting, inserting, replacing an array
var arr=[' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' G '];// change the original array
//alert (Arr.slice (2));// from 2 begin to intercept until the end, 2 it means subscript.
//alert (Arr.slice (2,5));// not included 5 the location
//alert (Arr.slice ( -4,-1));// negative inverse number, -1 Start, note the order of the numbers
Alert (Arr.slice (5,-1));//f
Alert (Arr.slice (5,-2));//
// Delete, insert, replace
Alert (Arr.splice (2));
/*alert (Arr.splice (2,1, ' OK '));// Replace
Alert (arr); */
Integer array / string array / Object array / two-dimensional array
javascript-understand 05? concept and definition of arrays