built-in objects in JavaScript
1.Array
2.String
3.Math
4.Date
Arrays in JavaScript
Learning Goals
1. Master any array creation
2. Mastering the reading and writing of numeric elements
3. Mastering the Length property of an array
How to create an array
There are two basic ways to create an array:
1. using the Array constructor
syntax:new Array()
Parentheses () Description:
(1) know in advance the number of items to be saved in the array
(2) to pass an array of items to a constructor in the array
2. use array literal notation : the square brackets [] of a pair of packet array items , separated by commas between multiple array items.
Reading and writing of array elements
when reading and setting values, use square brackets [] and provide the appropriate index
Description: Index is an integer starting at 0
Array length
Syntax:array.length
function: Gets The length of an array of arrays
return value: Number
Description
1. by setting legth You can remove an item from the end of the array or add a new item to the array.
2. when a value is placed above the current array size, the array recalculates its length value, which is equal to the last item's index plus 1.
Learning Goals
Master the Stack method of the array:
1.push ()
2.unshift ()
3.pop ()
4.shift ()
Push ()
Grammar:
Arrayobject.push (newele1,newele2,..., Newex)
Function:
add its parameter order to the tail of the arrayobject.
return value:
Adds the specified value to the new length after the array.
Unshift ()
Grammar:
Arrayobject.unshift (newele1,newele2,... Newex)
Function:
add its parameter order to the beginning of the arrayobject.
return value:
Adds the specified value to the line length after the array.
Pop ()
Grammar:
Arrayobject.pop ()
Function:
Delete The last element of Arrayobject
return value:
The element that was deleted
Shift ()
Grammar:
Arrayobject.shift ()
Function:
Delete the first element in a arrayobject
return value:
The element that was deleted
Learning Goals
1. Mastering the conversion method of the array
2. Mastering the reordering method of arrays
Join ()
Grammar:
Arrayobject.join (separator)
Function:
Used to put all the elements in an array into a string.
return value: String.
Reverse ()
Grammar:
Stringobject.reverse ()
Function:
Used to reverse the order of elements in an array.
return value: Array
Sort ()
Grammar:
Arrayobject.sort (SortBy)
Function:
Used to sort the array elements.
return value: Array
Description
1. even if each item in the array is a numeric value,the sort () method compares the string.
The 2.Sort() method can accept a comparison function as a parameter.
Learning Goals
1. Learn how to manipulate arrays:
Concat ()
Slice ()
Concat ()
Grammar:
Arrayobject.concat (Arrayx,arrayx,..., Arrayx)
Function:
Used to link two or more arrays.
return value:
Array
Slice()
Grammar:
Arrayobject.slice (Start,end)
Function:
Returns the selected element from an existing array.
Parameters:
Start(required) specifies where to start the selection, and if it is negative, it specifies the position from the end of the array.
End(optional) specifies where to end the selection, which is an array subscript for the end of the array afraid fragment.
Description
1. If End is not specified , then the segmented array contains all elements from start to end of the array.
2. If there is a negative number in the parameters of the slice () method, the corresponding position is determined with the array length plus the numbers.
return value: Array.
Learning Goals
1. Master using the Splice () method to delete array items
2. Master inserting array items using the splice () method
3. Mastering The substitution of array items with the splice () method
Delete
Grammar:
Arrayobject.splice (Index,count)
Function:
deletes 0 or more elements starting at index.
return value:
Contains an array of elements that have been deleted.
Description
Count is the number of items to be deleted, and if set to 0, the item is not deleted.
if not set, all values starting from index are deleted .
Insert
Grammar:
Arrayobject.splice (index0,item1,....., ItemX)
Function:
Inserts a value at the specified position
Parameters:
Index: start position
0: Number of items to delete
ITEM1....ITEMX: The item to insert
return value: Array
Replace
Grammar:
Arrayobject.splice (index,count,item1,...., ItemX)
Function:
Inserts a value at the specified location and deletes any number of items at the same time
Parameters:
Index: start position
Count: number of items to delete
Item1,... ItemX: The item to insert
Return value: The item removed from the original array (returns an empty array if no items were deleted)
Learning Goals
1. Master The two-location method that ECMAScript is added to an array instance:
IndexOf ()
Lestindexof ()
IndexOf ()
Grammar:
Arrayobject.indexof (Searchvalue,startindex)
Function:
Search backwards from the beginning of the array (position 0).
Parameters:
Searchvalue: must be, the item to find;
StartIndex: Optional, start position index.
return value:
Number, finds the position of the item in the array, and returns -1 without finding the case .
Lestindextof ()
Syntax :
Arrayobject.lastindexof (Searchvalue,startindex)
Function:
Looks forward from the end of the array.
Parameters:
Searchvalue: Must, the item to find
StartIndex: Optional, index of start position.
return value:
Number, finding the position of the item in the array, without finding the case issued back to -1.
Description
1. when comparing the first parameter to each item in the array, the strict equality operator is used, that is, the items required for the lookup must be strictly equal.
2. the location method of the array is ECMAScript for the number of instances, so the supported browsers are only:
ie9+,firefox2+,Safari3,Opera9.5,Chrome .
Built-in objects in JavaScript -8-array-1