JS built-in objects

Source: Internet
Author: User
Tags rounds

String object: A String object that provides properties and methods for manipulating a string.

Array object: Arrays object that provides properties for array manipulation and is illegal.

Date object: A DateTime object that can obtain the system's datetime information.

Boolean object: A Boolean object, a Boolean variable that is a Boolean object.

Number object: A numeric object, a numeric variable is a numeric object.

Math object: A Mathematical object that provides properties and methods for mathematical operations.

String object:

Length: string lengths.

toLowerCase (): Converts the letters in a string to lowercase.

toUpperCase (): Converts the letters in a string to uppercase.

CharAt (): Returns the character at the specified position.

IndexOf (): Returns the position where the specified substring first appears in the original string. If not found, returns-1.

LastIndexOf (): Returns the location of the last occurrence of the specified substring in the original string. If not found, returns-1.

SUBSTR (): Extracts the specified number of characters from the starting index number in the string.

SUBSTRING (): Extracts the characters between two specified index numbers in a string (the characters in the last position are not extracted).

Split (): Splits the string into an array.

Array object:

1. An array variable is an array object.

2. Properties and methods:

Length: The number of array members.

Join (): merges the array elements. Put all the elements of the array into a string. element is delimited by the specified delimiter.

Reverse (): Reverses the order of the elements in the array.

Shift (): the head popup element. Deletes and returns the first element of the array. (unlike delete array[i]; Delete can only delete the element value, the occupied space is still, the total length is unchanged. )

Unshift (): The head is pressed into the element. Adds one or more elements to the beginning of the array and returns the new length.

Push (): the tail is pressed into the element. Adds one or more elements to the end of the array and returns the new length.

Pop (): Tail popup element. Deletes and returns the last element of the array.

Date object:

1. Create a Date object:

1 //(1). Create a Date object with the current time without any parameters2 varDateobj =NewDate ();3 4 //(2). Create a Date object with a specified timestamp5 //      time stamp refers to the total number of milliseconds since GMT January 1, 1970 0:0 0 seconds (Beijing time January 1, 1970 8:0 0 seconds) until now6 varDateobj =NewDate (60000);7 8 //(3). Create a Date object of the specified day9 varDateobj =NewDate ("2016/11/04 12:21:00");Ten  One //(4). Specify multiple numeric parameters A //      The order is: year, month, day, time, minute, second. The year, the month and the day are necessary.  - varDateobj =NewDate (2016 + 100, 11, 24, 10, 20, 0);//creates a Date object with a datetime of November 24, 2116 12:21 0 seconds

2. Properties and methods:

getFullYear (): Gets the four-bit year.

GetMonth (): Gets the month (0-11).

GetDate (): Gets the number (1-31).

GetHours (): Gets the number of hours (0-23).

Getminutes (): Number of minutes (0-59).

Getseconds (): Number of seconds (0-59).

Getmilliseconds (): MS (0-999).

GetDay (): Week (0-6,0 for Sunday).

GetTime (): Timestamp. Millisecond value from GMT January 1, 1970 to the present.

Math Object

1. The Math object is a static object. When using the Math object, you do not need to wear an instance.

2. Properties and methods:

Math.PI: Pi.

Math.Abs (): The absolute value of the returned number.

Math.ceil (): Rounding up. (integer plus 1, decimal removed). such as: Math.ceil (10.2) = = 11

Math.floor (): Rounding down. (remove decimals directly). such as: Math.floor (9.88) = = 9

Math.Round (): Rounds the number to the nearest integer.

Math.pow (x, y): power function. X is the Y-square.

MATH.SQRT (): To find the square root.

Math.random (): Returns a random floating-point number between 0 and 1.

Number Object

1. A numeric variable is a numeric object.

2. Properties and methods:

ToFixed (): Converts a numeric value to a string and rounds it, preserving the decimal number of the specified digits.

JS built-in objects

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.