JS Basics 5

Source: Internet
Author: User

Array Arrays:

Both the Unshift () and push () methods add elements to the array, the former to the beginning, and the latter to the end. Returns the new length of the array.

The shift (), Pop () method is the element that is removed from the array, which is the first element removed, and the latter is the element that is removed most later. is the element that returns the removal.

These methods have been written several times and forgotten for some time. Simply look directly at the API simple rough, with more natural to remember.

String object:

The String object is used to manipulate text.

In fact, any string constant is a string object that can be used directly as an object.

You can get the length of a string by using the Length property.

var len = "Kobe"; alert (len.length)//4

The CharAt () method returns the character at the specified position.

var kobe = "Kobe"; var str = Kobe.charat (2); B

The following two methods are to get the string, which is passed in the specified length, which is the position of the incoming start and end.

var str = ' Hello '; alert (Str.substr (0,2);//The number of start digits, intercept length, returns the ' he ' alert (str.substring (0,3))//The position of the incoming start, end position < 3, the return is ' hel

IndexOf () returns the position of the specified string in the first occurrence of the string. LastIndexOf () returns the location of the last occurrence of the specified string in the string.

var kobe = "Kobebe"; var index = Kobe.indexof ("O"); 1
var l_index = kobe.lastindexof ("E"); 5

toLowerCase () is used to convert a string to lowercase.

toUpperCase () is converted to uppercase.

A BOM refers to the browser object model, which provides objects that interact with the browser window.

The Window object represents the entire browser window.

Timers are a very common tool.

SetInterval () can set the cycle timer, clearinterval () can clear the cycle timer.

var timer = setinterval (function () {},30);
Clearinterval (timer);

SetTimeout () is a single timer, cleartimeout () can clear a single timer.

var timer = setTimeout (function () {},1000); cleartimeout (timer);

 

The history object is a child of the Window object, corresponding to the browser's historical record.

The most common is history.back ().

This method can be returned to the previous page.

The Navigator object contains information about the Web browser, which is also a property of the window, which can be referenced by window.navigator or navigator.

var info = navigator.useragent ();

  

The DOM Document Object model, which defines the interface for manipulating document objects.

The DOM represents an HTML document as a family tree, using tokens such as parent, child, sibling (brother) to indicate the relationship between the members of the household.

The nodes are divided into:

1. ELEMENT nodes

ELEMENT nodes such as <body> <p> <div> elements that form the structure of the document in the document layout

2. Text node

A text node refers to the contents of an element node, but not all element nodes contain text nodes.

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.

Queryselector () is the new method of HTML5, and by passing in a legitimate CSS selector, you get the first element that meets the criteria.

Document.queryselector (". Text");

  

JS Basic 5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.