There are three ways to delete an array object:
Pop (); Removes the last element and returns the element value
Shift (); Removes the first element and returns the element value, and the elements in the array are automatically moved forward
Splice (0,2); Removes the specified number of DeleteCount elements from the specified position deletepos, returning the removed element as an array
With these three ways we can delete the elements in the array by pressing the
var del = ["AA", 23,345,56,34, "BB"];var del_last = Del.pop (); ["BB"]var Del_first = Del.shift (); ["AA"]var Del_arr = Del.splice (0,2); [23,345]document.write (DEL);//[56,34]
The String object is used to manipulate text. Any string constant is a string object that can be used directly as an object.
The string object has the length property, and we can get the lengths of the strings by using length property.
var str = "Hello"; var str2 = "Hello"; alert (str.length);//Output 5 alert (str2.length);//Output 2
The string extraction method has
The 1.charAt () method returns the character at the specified position.
The 2.substr () method, which has two parameters, the first one is the number of initial digits passed in, the second is the truncated length, and the truncated string is returned.
3. Substring () method, there are two human parameters, respectively, the position of the beginning and the end of the position, the truncated string is returned.
var str = "HELLO world"; var n = str.charat (2); Ealert (Str.substr (0,2);//healert (Str.substring (0,3))//hel
The methods for finding strings are:
1. IndexOf ()//returns the position of the first occurrence of a specified string value in the string.
2.lastIndex () method//Find the position where the character last appeared
3. The search () method finds the specified string or substring that matches the regular expression
var str= "Hello World, Welcome to the universe"; Alert (Str.indexof ("Welcome");//13alert (Str.lastindexof (' e '));//35
The substitution method for a string has replace, which replaces some characters with some character in a string, or replaces a substring that matches a regular expression.
var str= "Visit microsoft!"; var n=str.replace ("Microsoft", "W3cschool");//"Visit w3cschool!"
In addition to the above method, the string also has stitching, the character of the case of conversion, they are 1.concat,2.+ to judge the left and right sides, if one side is a string, then the + number for the stitching function 3.toLowerCase () method is used to convert the string to lowercase, The 4toUpperCase () method is used to convert a string to uppercase.
A BOM (Browser object model) that provides objects that interact with a browser window.
First, Window object
The Window object represents the entire browser window. The method has
1. System message Box: alert ();
2. Confirmation dialog: Confirm () The method returns a Boolean value, and if clicked OK returns True, click Cancel to return false;
3. Input dialog: prompt () If you click OK to return the value in the text box as a function value, click Cancel to return null;
4. Open a new Window window.open ();
5. Timer Loop timer settimeout and single timer setinterval. Both of these timers receive two parameters, which are code strings or functions that need to be executed, which is the time, in milliseconds. To clear the timer, use Cleartimeout () to clear the single timer and clearinterval to clear the loop timer. The parameter is the variable name of the timer
var A=0;var t=setinterval (function () { a++;console.log (a);},1000); SetTimeout (Clearinterval (t), 5000);
The child object of the History Object window object, corresponding to the browser's historical record.
Window.history.go (-1);//returns to the previous page, and the page returned is determined by the parameters in parentheses
Window.history.go (1);//Enter the next page, determined by the parameters
History.back ();//Return to previous page
History.forward ();//Go to the next page
The Location object is also a child of the Window object, through which you can get or set the current address of the browser.
1. Jump to another page
Window.location.href = "http://www.163.com";
Location.href = "http://www.163.com";
2. Reload page (refresh)
Location.reload ();
The Navigator object contains information about the Web browser, which is also a property of the window, can be referenced with window.navigator, or it can be referenced with navigator
Cases:
var info = Navigator.useragent;alert (info);//Get the browser internal code, name, operating system and other information
The DOM Document Object model, which defines the interface for manipulating document objects. It represents an HTML document as a family tree, using tokens such as parent, child (son), sibling (brother) to indicate the relationship between the members of the household (each element).
First, the node
A document is a collection of nodes. There are three types of nodes:
1. ELEMENT nodes
ELEMENT nodes, such as <body> <p> <div>, are tags in HTML that form the structure of the document in the layout of the document.
2. Text node
A text node refers to the contents of an element node, but not all of the element nodes contain text nodes, and the elements that usually contain text nodes are paired, and the text nodes are between label pairs.
3. Attribute nodes
Elements have more or less attributes, and the function of the attribute is to make a more specific description of the element. Attribute nodes are always included in the element node.
<p title= "Show me Here" > This is a paragraph </p>//element node is p tag, attribute node is title, text node is: this is a paragraph.
HTML5 adds two ways to get a Document object, 1. Queryselector (). 2. Queryselectorall (). Both are obtained by passing in a legitimate CSS selector to the element that meets the criteria. The first returns only the first element, and the second returns all the groups of objects that meet the criteria. It is important to note that the above two methods cannot be used to find elements with pseudo-class state, such as Queryselector (': hover '), and will not get the result of the period.
Document.queryselector ("#test"); Returns the first Divdocument.queryselectorall with ID test (' div.foo ');//returns all DIV element objects with the Foo class style
Addition of array object elements, string objects, BOM objects, and acquisition of document objects