stringObject.charAt(index) method: Returns the character at the specified index position.
The stringObject.slice(start,[end]) and stringObject.substring(start,[end]) methods both accept two parameters, which are the starting position and the ending position of the substring, and return the value between the two. string, excluding the string at the terminating position. If the second argument is not specified, it defaults to the length of the string, from the starting position to the end of the string.
【Difference】The main difference between these two methods is the different processing of negative numbers. For slice(), negative parameters are counted from the end of the string, while substring() directly ignores negative numbers and treats them as 0, with 0 as the starting position and positive numbers as the ending position. For example: substring(2,-3) is equivalent to substring(0,2)
stringObject.substr(start,[length]) method: Returns a string starting from the subscript start and with length as the length.
stringObject.indexOf(searchStr,[fromIndex]) method: Returns the string searchStr and searches for the index number that first appears in the stringObject string from fromIndex. If Str is not included in stringObject, -1 is returned. (Search from front to back)
stringObject.lastIndexOf(searchStr,[fromIndex]) method: Return the string searchStr from fromIndex (counting from the end) to search forward for the index number that first appears in the stringObject string. If Str is not included in stringObject, -1 is returned. (Search from back to front)
parseInt(string,[radix]) function can parse a string and return an integer. radix indicates that it needs to be converted into a decimal number (optional), and the default is decimal.
parseFloat(string) function can parse a string and return a floating point number.
Declaration of arrays in JavaScript:
new Array();
new Array(size);
new Array(element0, element0, ..., elementn);
[element0, element0 , ..., elementn];
arrayObject.join([separator]) method returns a string. The string is generated by converting each element of the arrayObject to a string and then concatenating the strings, inserting the separator string between the two elements.
The stringObject.split(separator,[howmany]) method returns an array created by splitting the string stringObject into substrings at the boundaries specified by separator. howmany represents the maximum length of the returned array (optional). stringObject.split("") can split the string stringObject into letters.
arrayObject.reverse() method is used to reverse the order of elements in an array. No return value.
arrayObject.sort() method is used to sort the elements of the array. No return value.
JavaScript definition function
function functionName([arg0,arg1,…,argN])
{
statements
[return[expression]]
}
Accessed with arguments object function parameters. For example, arguments[0] can access the value of the first parameter.
Math.random() method can return a random number between 0 ~ 1.
BOM (Brower Object Model) browser object model
includes: window, document, location, navigator and screen
Commonly used properties and methods of Window objects are:
window.moveBy(dx,dy) : Move the browser window equivalent to the current position horizontally dx pixels to the right and vertically down dy pixels;
window.moveTo(x,y): Move the browser window to (x,y) of the user screen );
window.resizeBy(dw,dh): Relative to the current size of the browser window, increase the width by dw pixels and the height by dy pixels;
window.resizeTo(w,h): The width of the browser window is adjusted to w pixels, and the height is adjusted to h pixels;
window.open([newWindowURL],[newWindowName],[feature1,feature2…]): Open a new window. newWindowName is equivalent to the target attribute of the tag.
windowObject.opener: access the original window that opened the windowObject;
window.close(): close the current window;
window.status="...": set the status bar text;
window.alert( "..."): pops up a prompt message;
window.confirm("..."): pops up a confirmation box;
window.prompt([text],[defaultText]): pops up an input prompt box, defaultText is the default text (Optional);
window.history.go(-1)/window.history.back(): Go back one page;
window.history.go(1)/window.history.forward(): Go forward one page.
The Document object is a property of the Window object and can be accessed through the window.document property.
Common method: document.write(“…”)
The Location object is a property of the Window object and can be accessed through the window.location property.
Commonly used attributes: location.href=URL
Navigator object
Commonly used attributes: navigator.userAgent (Usually the browser’s judgment is done through this attribute.)
Screen object is also a Window object a property.
Commonly used attributes:
screen.availHeight: the screen height that the window can use;
screen.availWidth: the screen width that the window can use;
screen.colorDepth: the number of digits the user can use to represent the color;
screen.height: screen height;
screen.width: screen width.