String method, return value, whether to change the original string:
The 1charAt () method returns the character at the specified position.
Do not change the original string
JavaScript does not have a character data type that differs from a string type, and the returned character is a string of length 1;
Note: The subscript for the first character in a string is 0. If the parameter index is not between 0 and String.Length, the method returns an empty string.
2concat () method to concatenate two or more strings and return the concatenated string
Do not change the original string
Syntax: Stringobject.concat (STRINGX,STRINGX,..., stringx);
Note: The original string has not changed, and the use of the "+" operator for string connection operations is usually easier.
The 3 indexOf () method returns the subscript of the position where a specified string value first appears in the string.
Do not change the original string
Syntax: Stringobject.indexof (Searchvalue,fromindex) The second argument can be omitted, which is the location where the setting starts to be retrieved;
Note: indexOf () is case sensitive, and if not found, the return value is-1 (the reason for returning 1 is to maintain the data type consistency principle);
The 4lastIndexOf () method returns the subscript of the last occurrence of a specified string value;
Do not change the original string
That is, the specified position in a string is searched forward from behind.
Syntax: Stringobject.lastindexof (Searchvalue,fromindex) The second value is an optional parameter, which is where the setting starts to retrieve
The 5Slice () method extracts a portion of a string and returns the extracted part with a new string.
Does not change the original string;
Syntax: Stringobject.slice (start,end);
Start subscript of the fragment to extract. If it is a negative number, the parameter specifies where to start from the end of the string. That is,-1 refers to the last character of the string, 2 refers to the second-lowest character, and so on.
End subscript at the end of the fragment to be extracted immediately. If this parameter is not specified, the substring to be extracted includes the string from start to the end of the original string. If the parameter is negative, it specifies the position from the end of the string.
The return value is: a new string. Includes the string Stringobject all characters from start (including start) to end (not including end).
Note: The methods of the String object Slice (), substring (), and substr () (not recommended) can return the specified part of the string. Slice () is more flexible than substring () because it allows negative numbers to be used as arguments. Slice () differs from substr () because it specifies a substring with a position of two characters, and substr () specifies a substring with a character position and length.
Also note that String.slice () is similar to Array.slice ().
The 6Split () method is used to split a string into a string array. Does not change the original string;
Syntax: Stringobject.split (Separator,howmany);
Separator required. A string or regular expression that splits stringobject from where specified by the parameter.
Howmany is optional. This parameter specifies the maximum length of the returned array. If this parameter is set, the returned substring will not be more than the array specified by this parameter. If this argument is not set, the entire string is split, regardless of its length.
Note: If you use an empty string ("") as a separator, each character in the Stringobject will be split.
Note: The action performed by String.Split () is the opposite of what Array.join does.
The 7 substr () method extracts a specified number of characters from the start subscript in a string.
The return value is a new string;
The original string did not change;
Syntax: Stringobject.substr (start,length);
Start Required. The starting subscript for the substring to extract. Must be numeric. If it is a negative number, the argument declares the position from the end of the string. That is,-1 refers to the last character in the string, 2 refers to the second-lowest character, and so on.
Length is optional. The number of characters in the substring. Must be numeric. If this argument is omitted, then the string from the beginning of the stringobject to the end is returned.
Note: ECMAscript does not standardize the method and therefore opposes its use.
The 8substring () method is used to extract the character of a string intermediary between two specified subscripts.
Stringobject.substring (Start,stop);
The original string did not change;
Return value: A new string that contains the string value of the Stringobject
A substring whose contents are all characters from start to stop-1, with a length of stop minus start.
Start Required. A nonnegative integer that specifies the position of the first character of the substring to be extracted in the stringobject.
Stop is optional. A nonnegative integer that is 1 more than the last character of the substring to extract in Stringobject.
If this argument is omitted, the returned substring continues until the end of the string.
The 9toLowerCase () method is used to convert a string to lowercase.
Stringobject.tolowercase ();
The original string does not change;
Return value: A new string in which all uppercase characters in Stringobject are converted to lowercase characters.
The toUpperCase () method is used to convert a string to uppercase.
Syntax: Stringobject.touppercase ();
The original string does not change;
Return value: A new string in which all lowercase characters in stringobject are converted to uppercase characters.
---------------------------------------------------------------------------------
String method, return value, whether to change the original string:
The
1 concat () method is used to concatenate two or more arrays. The
method does not alter an existing array, but only returns a copy of the concatenated array.
Arrayobject.concat (Arrayx,arrayx,......, arrayx)
Arrayx required. The parameter can be a specific value, or it can be an array object. can be any number. The
returns a new array. The array is generated by adding all the Arrayx parameters to the Arrayobject. If the argument for the concat () operation is an array, then the element in the array is added, not the array. The
2 Join () method is used to put all the elements in the array into a string.
Do not change the original array;
Syntax: arrayobject.join (separator);
Separator optional. Specifies the delimiter to use. If this argument is omitted, a comma is used as the delimiter. The
returns a string. The string is generated by converting each element of Arrayobject to a string and then connecting the strings to insert a separator string between the two elements. The
3 Pop () method is used to delete and return the last element of the array.
Syntax: Arrayobject.pop ();
changes the original array;
return value: The last element of Arrayobject. The
Note: the Pop () method removes the last element of arrayobject, reducing the length of the array by 1 and returning the value of the element it deletes. If the array is already empty, pop () does not change the array and returns the undefined value. The
4 push () method adds one or more elements to the end of the array and returns the new length. The
changed the original array;
Syntax: Arrayobject.push (newelement1,newelement2,...., newelementx)
Newelement1 required. The first element to add to the array. The
Newelement2 is optional. The second element to add to the array. The
Newelementx is optional. You can add multiple elements.
Return value: The new length after the specified value is added to the array.
Note: The push () method adds its parameter order to the tail of the arrayobject. It modifies the arrayobject directly, rather than creating a new array. The push () method and the Pop () method use the advanced post-stack functionality provided by the array.
5The reverse () method reverses the order of the elements in the array.
Syntax: Arrayobject.reverse ();
The method will change the original array;
6The shift () method removes the first element from the array and returns the value of the first element.
Arrayobject.shift ();
The method changes the original array;
Return value: The value of the original first element of the array.
Note: If the array is empty, then the shift () method will not take any action and return the undefined value.
7The slice () method returns the selected element from an existing array.
Syntax: Arrayobject.slice (start,end);
The method does not change the original array;
Start Required. Specify where to start the selection. If it is a negative number, it specifies the position from the end of the array. In other words, 1 refers to the last element, 2 refers to the second-lowest element, and so on.
End is optional. Specifies where to end the selection. The parameter is the array subscript at the end of the array fragment. If this parameter is not specified, then the segmented array contains all elements from start to end of the array. If this parameter is a negative number, it specifies the element starting from the end of the array.
Return value: Returns a new array containing elements from start to end (excluding the element) in the Arrayobject.
Note: Use a negative value to select an element from the tail of the array.
Note: If end is not specified, then the slice () method selects all elements from start to the end of the array.
8The sort () method is used to sort elements of an array.
Arrayobject.sort ();
Change the original array;
Return value: The original array after the change;
Arr.sort (function (n,m) {
return n-m;
}
9The splice () method is used to insert, delete, or replace elements of an array.
Syntax: Arrayobject.splice (index,howmany,element1,....., elementx);
Return value: If the element is removed from Arrayobject, the array containing the deleted element is returned.
var arr = [1,3,3,2,5,9,12,21,11];
Console.log (Arr.splice (2,2))---->[3,2]
Console.log (arr)---->[1, 3, 5, 9, 12, 21, 11]
The method changes the original array;
Index required. Specifies where to add/remove elements from.
This parameter is the subscript that begins inserting and/or deleting an array element, which must be a number.
Howmany required. Specifies how many elements should be deleted. Must be a number, but it can be "0".
If this parameter is not specified, all elements from index start to the end of the original array are deleted.
Element1 is optional. Specifies the new element to be added to the array. Start the insertion from the subscript at index point.
Elementx is optional. You can add several elements to an array.
TenThe ToString () method converts the array to a string and returns the result.
Syntax: arrayobject.tostring ();
Do not change the original array;
Return value: The string representation of the Arrayobject. The return value is the same as the string returned by the join () method without parameters.
The Unshift () method adds one or more elements to the beginning of the array and returns the new length.
The method changes the original array
Syntax: Arrayobject.unshift (newelement1,newelement2,...., newelementx)
Newelement1 required. The first element to add to the array.
Newelement2 is optional. Adds a second element to the array.
Newelementx is optional. You can add a number of elements.
Return value: The new length of the arrayobject.
---------------------------------------------------------------------------------
Dom
1 Getting elements:
document.getElementById (' ID name ')
Gets the one that the parent must be document
document.getElementsByTagName (' tag name ')
Gets a group that the parent is not necessarily a document
Document.getelementsbyclassname (' Class name ')
A group of advanced browsers
Document.getelementsbyname (' name ')
A set
Document.queryselector (' selector ')
Advanced Browser One
Document.queryselectorall (' #div1 p ')
A set
Parent. Children
Gets the first level of the child
Childnode
can get text nodes
ParentNode
FirstChild
Recognize text nodes in advanced browsers
Only element nodes are recognized in low-level browsers
Firstelementchild
ELEMENT nodes are identified in the Advanced browser
In a low-level browser is undefined
LastChild
Lastelementchild
PreviousSibling
Previouselementsibling
NextSibling
Nextelementsibling
2 Creating elements
Document.createelement (' tag name ')
Note: must be created under document
3 inserting elements
Parent. appendchild (Child)
Parent. Insertbefor (who to put, who to insert before)
Note: the parent. Insertbefor (who, NULL) is executed by default AppendChild
4 Deleting an element
Parent. RemoveChild ()
5 Cloning elements
Obj.clonenode () clones only elements
Obj.clonenode (True) contains content;
6 Information offsettop of objects
Offsetleft
Relative to the location of the parent
GetPos (obj) {
var l=0;
var t=0;
while (obj) {
L+=obj.offsetleft;
T+=obj.offsettop;
Obj=obj.offsetparent;
}
return {left:l,top:t}
}
Offsetwidth
Offsetheight
The width of the box model is obtained.
ScrollHeight
Scrollwidht
If the content does not exceed the box, get the high +padding of the box, if it exceeds the width of the content of the acquired object
OffsetParent
The parent of the location
The highest level is the body on the upward is null
ParentNode
Parent of structure
The highest level is document, which is null on the Web
7 Information Visibility area of the page
Document.documentELement.clientWidth
Scrolling distance
Document.documentELement.scrollTop
Not compatible with Chrome
Document.body.scrollTop
Compatible with Chrome
8 Getting the difference of height
. style. GetStyle offsetheight
100px 100px 100
String string number
In the case of hidden conditions can be obtained can get 0
Common Array, string method summary & get element, DOM manipulation