<>JavaScript study ( Eighty-eight )— liver failure Summary of array knowledge points , Super detail !!!
Make a little progress every day Xiao Wang, come on !!!
<> one , Concept of array
* The so-called array refers to the continuous storage space opened up in memory to store a large amount of data
* Arrays can store a set of related data together , And provide convenient access ( obtain ) mode .
* An array is a collection of data , Each of these data is called an element , Any type of element can be stored in the array . Arrays are an elegant way to store a set of data under a single variable name .
<> two , Classification of arrays
* From the number of Subscripts : One dimensional array , Two dimensional array , Multidimensional array
* Type classification from subscript : Indexed array ( Subscript is array type ), Associative array ( Subscript is character type )
<> three , How arrays are created
<> mode 1: Using construction method to create
format :var The name of the array =new Array( value 1, value 2....);
<> mode 2: Create with literal form var Array name =[ value , value , value …];
<> four , Operation of array elements : increase , Delete , change , check
*
increase : Array name [ subscript ]= value ; Subscripts are values that are not in the existing subscripts of the array
*
Delete :delete Array name [ subscript ]; This deletion method only empties the data in the location , But the location was not deleted
*
change : Array name [ subscript ]= value ; The subscript is the subscript of the data to be changed
*
check : Array name [ subscript ]; If the subscript does not exist , Then return undefined
<> five , Array element
* Array element : The so-called array element is each value stored in the index group , Each element in the array has its own number , This number is called a subscript / Indexes / Angle mark
be careful : The subscript of the element in the array is from 0 Beginning , That is, the subscript of the first element is 0, The subscript of the last element is the length of the array -1.
<> six , Traversal array
ergodic : Each element in the array is accessed once from beginning to end ( Similar to student roll call ), Can pass for The circular index traverses each item in the array
<> seven , New element in array
<> eight , Four ways to traverse an array
<>( one ), utilize for loop
<>( two ), utilize for in Loop through array
<>( three ), utilize for of Traversal array
<>( four ), utilize forEach Method traverses the array
<> nine , Assign a value to an array
How to assign values to arrays , That is, add array elements , Assigning values to arrays using random functions , The format is as follows :
var num=parseInt(Math.random() *( Maximum +1- minimum value )+ minimum value );
<> ten , Array comparison
* Js There are two main types of data : Basic data type , Reference data type
* Basic data type : Numerical type (number), character (String), Boolean (BOOlean),undefined,null
* Reference data type : array , function , object
Data of reference types are not equal to each other See the figure below
<> eleven , Common properties and methods of array objects ( function )
<>1,length attribute
1) effect : Gets or sets the length of the array
2) Gets the format of the :
Array name .length
3) Format :
Array name .length= New length ;
<>2,push method
1) effect : Add an element at the end of the array
2) format : Array name .push( value 1, value 2, value 3…);
3) Return value : New length of array
<>3,pop method
1) effect : Delete elements at the end of the array
2) format : Array name .pop();( No parameter )
3) Return value : Deleted element
<>4,unshift method
1) effect : Add element to array header
2) format : Array name .unshift( value 1, value 2, value 3…);
3) Return value : New length of array
<>5,shift method
1) effect : Delete array header element
2) format : Array name .shift();
3) Return value : Deleted element
<>6,concat method
1) effect : Realize the splicing between arrays
2) format : Array name 1.concat( Array name 2, Array name 3, Array name 4, value 1, value 2…);
3) Return value : New array after splicing , Note that the original array is not affected
<>7,join method
1) effect : Convert array to characters
2) format : Array name join(‘ Separator ’);
3) Return value : Converted String
4) Delimiters can be omitted , If omitted , Comma is used as separator by default , If necessary, separate the array elements without delimiters , Then it can be used in join Parameter position write "";
<>8,slice method
1) effect : Truncate the new array from the array
2) format : Array name .slice(begin,end);
3) Return value : Intercepted new array
4) be careful :
begin Indicates the start subscript
end Indicates the end subscript , When intercepting end The corresponding value is not intercepted , That is, including the head but not the tail .
end Can be omitted , Indicates from begin Until the end
begin and end Can be omitted , If omitted, the array is copied
<>9, splice method
<> effect : Incrementing an array , Delete , Modified operation
*
Incremental format : Array name .splice( subscript ,0, Value to insert );
*
The returned value is an empty array , In addition, you can insert multiple values at once , Values are separated by commas
*
Deleted format : Array name .splice( subscript , number );
*
The return value is a new array formed by the deleted array elements
*
be careful delete The value of the deleted element , and splice Values and spaces are deleted
*
Modified format : Array name .splice( subscript , number , New value );
*
The return value is a new array of modified elements
<> twelve ,toString method
* effect : Convert array to string
* format : Array name .toString()
* Return value : A string consisting of array elements , Elements are separated by commas
<> thirteen ,indexOf method
* effect : Finds the specified element in the array from left to right , If yes, the subscript of the element is returned , without , Then return -1
* format : Array name .indexOf( Value to find );
* be careful : If there are multiple values to find in the array , Then stop searching after finding the first one
<> fourteen ,lastIndexOf method
* effect : Plex right to left finds the specified element in the array , If any, returns the subscript of the element , If not returned -1
* format : Array name .lastIndexOf( Value to find );
* be careful : If there are multiple values to find in the array , Then stop searching after finding the first one
<> fifteen ,reverse method
* effect : Inverts the position of elements in an array
* format : Array name .reverse();
* Return value : The original array with the order reversed
<> sixteen , isArray method
* effect : Determine whether a data is an array
* format :Array.isArray( Data to judge );
* Return value : true( Is an array ),false( Not an array )
<> seventeen , sort method
*
effect : Sort the data in the array
*
Ascending order : Array name .sort(function(a,b){return a-b });
*
Descending order : Array name .sort(function(a,b){return b-a});
<> Friends Remember the third company , I'll remember you !!!
Technology
Daily Recommendation