Array of strings

String Array
Array Operation
Basic Operation (4)
Push () to add elements to the end of the array
parameters: To add the end of the array element number is not limited
Return Value: length of the array
pop () removes an element from the end of the array
Return value : element value removed
shift () removes an element from the front of the array
return value: value of elements removed
the unshift () to add elements to the front of the array
parameters: to array elements previously added, the number is not limited
return value: length of the array
splice ( ) is used anywhere in the array additions and deletions to the operating
parameters 1: operation start position index
parameter 2: the number of elements to be deleted
following parameter: element value (without corresponding to the number) added to the erasure position
return value: is remove new array of elements of
slice () copies elements from an array portion
parameter 1: index operation start position, 0 is the default
parameter 2: the index value (the value of the free end position) of the operation end position, the default length is
If parameter 1 and parameter 2 are not written, taken from the beginning to the end represents a default
return value: new copy of the array of elements
concat () array for Bonding operation
parameters: can add elements to the end of the array, if the incoming array element, the array will be successively placed
Return Value: returns a new array after connection
the indexOf () to find the index of the array element value of the specified
parameter 1: To Find the value of the element
Parameter 2: Find the start position of the index value, the default is 0
Return Value:
If found, returns the index of the first found, not found returns -1
Sort () which the array is in ascending or descending
ascending parameters:
function (a, b) {return a - b}
descending parameters:
function (a, B) {return B - a}
Reverse () inverted array
action: the elements of an array flip, such as an array [1, 2, 3] flipping result [. 3, 2,. 1]
toString () array into a string type
join () through a connector connected to the string array element - must have the
parameters: connector, the default is the comma, connected to
the return value: rear connector string
string operation
length string length representing the number of characters, numeric type
index operation
format 1: string [index]
format 2: .charAt string (index)
copy string operations
slice
parameter 1: operation start index location
parameter 2: the operating end position of the index (excluding end position)
the substring function and the same slice, usually to slice
substr
parameter 1: operation start position of the index
parameter 2: copy number of characters
indexOf
Param 1: string what you're looking
Parameter 2: Search for the beginning of the index value
Return Value: -1 not found, returns the first time the contents of the index to find the value of
attention to points
more characters in search character string composed of part, returns the index of the first character
2 If indexOf retrieve empty string '', would return to 0
the toUpperCase () uppercase string transfer
the toLowerCase () small letter string
replace () replacement function
parameter 1: to replace the content
parameter 2: replace what
split () according delimited string delimiter array
parameters: separator
return value: an array according to obtained delimiter
trim () remove the spaces at both ends of the string

Guess you like

Origin www.cnblogs.com/itxcr/p/11600121.html