Home  >  Article  >  Web Front-end  >  Detailed explanation of the use of js built-in methods and objects

Detailed explanation of the use of js built-in methods and objects

php中世界最好的语言
php中世界最好的语言Original
2018-04-23 10:52:441558browse

This time I will bring you a detailed explanation of the use of js built-in methods and objects. What are the precautions for the use of js built-in methods and objects? Here are practical cases, let’s take a look.

JSBuilt-in functions do not belong to any object, and these functions can be used directly anywhere in the JS statement. The commonly used built-in functions in JS are as follows:

1. eval(str) receives an expression in the form of a string and attempts to find the value of the expression. Expressions as parameters can take any legal operators and constants. If the parameters contain JS commands, these commands can also be executed as if these commands were part of the JS program.

2. parseInt(str,n) attempts to extract an integer from a string. An n integer can be appended to return an n-base integer. If there are characters other than numbers, symbols, decimal points, and exponent signs in the string, the conversion stops and the existing results are returned. If the first character cannot be converted, the function returns a NaN value.

3. parseFloat(str) attempts to extract a floating point value from a string. If there are characters other than numbers, symbols, decimal points, and exponent signs in the string, the conversion stops and the existing result is returned. If the first character cannot be converted, the function returns a NaN value.

4. isNaN() is used to determine whether it is a NaN value type. If it is a function, it returns true.

5. isFinite(number) can determine whether the parameter number is infinity. If so, the function returns false, otherwise it returns true.

6. escape() accepts a string, which may contain spaces, semicolons and other characters. The function converts a string into the cookie's internal representation. The function return value is this internal expression.

7. unescape() accepts a Cookie and converts its internal expression into an ordinary string form. JS functions can be divided into five categories: regular functions, array functions, date functions, mathematical functions, and string functions.

1. 9 regular functions

(1)alert function: displays a warning dialog box, including an OK button.

(2)confirm function: Display a confirmation dialog box, including OK and Cancel buttons.

(3)escape function: Convert characters into Unicode codes.

(4)eval function: calculates the result of an expression.

(5)isNaN function: Test whether (true) or not (false) is not a number.

(6)parseFloat function: Convert a string into dotted digital form.

(7)parseInt function: Convert the string into integer digital form (the decimal system can be specified).

(8)prompt function: Display an input dialog box, prompting to wait for user input.

(9)unescape function: Decode characters encoded by the escape function.

2. Array object 4 array functions

(1)join function: set the separator to connect array elements is a string.

(2)langth function: Returns the length of the array.

(3)reverse function: Reverse the order of array elements.

(4)sort function: Reorder array elements.

3. Data object 20 date functions

(1)getDate function: Returns the "day" part of the date, the value is 1~31.

(2)getDay function: Returns the day of the week, the value is 0~6, 0 means Sunday.

(3)getHours function: Returns the "hour" part of the date, the value is 0~23.

(4)getMinutes function: Returns the "minutes" part of the date, the value is 0~59.

(5)getMonth function: Returns the "month" part of the date, the value is 0~11.

(6)getSeconds function: Returns the "seconds" part of the date, the value is 0~59.

(7)getTime function: Returns the system time.

(8)getTimezoneOffset function: Returns the time difference in this region (the regional time difference between local time and GMT Greenwich Mean Time), in minutes.

(9)getYear function: Returns the "year" part of the date. The return value is based on 1900, for example, 1999 is 99.

(10)parse function: Returns the number of milliseconds since 0:00 on January 1, 1970 (local time).

(11)setDate function: Set the "day" part of the date, the value is 0~31.

(12)setHours function: Set the "hour" part of the date, the value is 0~23.

(13)setMinutes function: Set the "minutes" part of the date, the value is 0~59.

(14)setMonth function: Set the "month" part of the date, the value is 0~11. Among them, 0 represents January, ..., and 11 represents December.

(15)setSeconds function: Set the "seconds" part of the date, the value is 0~59.

(16)setTime function: Set time. The time value is the number of milliseconds since 00:00 on January 1, 1970.

(17)setYear function: Set the "year" part of the date.

(18)toGMTString function: Convert the date into a string, which is GMT Greenwich Mean Time.

(19)setLocaleString function: Convert date into string and local time.

(20) UTC function: Returns the number of milliseconds (GMT) since 0:00 on January 1, 1970.

4. Properties and functions of the Math object

The main properties are

Math.e (e natural logarithm)

Math.LN2 (natural logarithm of 2)

Math.LN10(natural logarithm of 10)

Math.LOG2E(e Logarithm, the base is 2)

Math.LOG10E(The logarithm of e, the base is 10)

Math.PI(π pi)

Math.SQRT1_2(1 /The square root value of 2)

Math.SQRT2(The square root value of 2).

There are 18 functions:

(1) abs function: Math.abs (the same below), returns the absolute value of a number.

(2) acos function: Returns the inverse cosine of a number, and the result is 0 to π radians (radians).

(3)asin function: Returns the arcsine value of a number, and the result is -π/2~π/2 radians.

(4)atan function: Returns the arctangent value of a number, and the result is -π/2~π/2 radians.

(5)atan2 function: Returns the polar coordinate angle value of a coordinate.

(6) ceil function: Returns the smallest integer value of a number (greater than or equal to).

(7)cos function: Returns the cosine value of a number, and the result is -1~1.

(8)exp function: Returns the power value of e (natural logarithm).

(9)floor function: Returns the maximum integer value of a number (less than or equal to).

(10)log function: natural logarithm function, returns the natural logarithm (e) value of a number.

(11)max function: Returns the maximum value of two numbers.

(12)min function: Returns the minimum value of two numbers.

(13)pow function: Returns the power of a number.

(14)random function: Returns a random value from 0 to 1.

(15)round function: Returns the rounded value of a number, the type is integer.

(16) sin function: returns the sine value of a number, and the result is -1~1.

(17)sqrt function: Returns the square root value of a number.

(18)tan function: Returns the tangent value of a number.

5. String object 20 string functions

(1)anchor function: Generate a link point (anchor) for use as a hyperlink.

(2)big function: Increase the font to size one, which is the same as the ... tag.

(3)blink function: Makes the string blink, which is the same as the ... tag result.

(4)bold function: Make the font bold, which is the same as the ... tag result.

(5) charAt function: Returns a character specified in the string.

(6) fixed function: Set the font to a fixed-width font, which is the same as the ... tag.

(7)fontcolor function: Set the font color, which is the same as the tag result.

(8)fontsize function: Set the font size, which is the same as the tag result.

(9)indexOf function: Returns the first index found in the string, starting from the left.

(10) italics function: Make the font italic, which is the same as the ... tag result.

(11)lastIndexOf function: Returns the first subscript index found in the string, starting from the right.

(12)length function: Returns the length of the string. (Without parentheses)

(13) link function: Generate a hyperlink, which is equivalent to setting the URL address of .

(14)small function: Reduce the font size by one size, which is the same as the ... tag.

(15)strike function: Add a horizontal line in the middle of the text, which is the same as the ... tag.

(16)sub function: Display the string as a subscript.

(17)substring function: Returns several characters specified in the string.

(18)sup function: Display the string as superscript.

(19)toLowerCase function: Convert the string to lowercase.

(20)toUpperCase function: Convert the string to uppercase.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Summary of JS array methods

What are the methods for defining classes in js

!=,==,!==,===Usage summary

The above is the detailed content of Detailed explanation of the use of js built-in methods and objects. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn