What are the common methods of JavaScript built-in objects?

青灯夜游
Release: 2023-01-06 11:16:47
Original
3071 people have browsed it

Commonly used methods of built-in objects: concat(), join(), pop(), shift(), slice(), splice(), push(), sort(), reverse(), toLocaleString( ), escape(), eval(), etc.

What are the common methods of JavaScript built-in objects?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Commonly used built-in objects in JS: Array object, Date object, string object, Global object

Commonly used methods in Array object:

  • concat( ) Indicates merging several arrays into one array

  • join()  Set the separator to connect the array elements into a string

  • pop() Remove the last element of the array

  • shift() Remove the first element of the array

  • slice(start, end) Return to the array A section of

  • splice() can be used to delete, insert, or replace

  • push() to the array Add a new element and return the latest length

  • sort() Sort the array

  • reverse() Reverse the order of the array

  • toLocaleString() Convert the array to a local string

Commonly used methods of Global objects:

Global properties and functions can be used All built-in JavaScript objects

  • escape()   Encoding string

  • eval()    Parse the string into JavaScript code and execute it

  • isNaN()                 

    ##parseFloat()   Parse a string and return a floating point number
  • number()   Convert the value of the object to a number
  • string()  Convert the value of the object to a string
  • Common methods of String object

  • charAt()      Return the specified index The character at the position

indexOf()       Search the string from front to back to see if it contains the specified string
  • lastIndexOf()   Search the string before to see if it contains the specified string
  • ##concat()    Concatenate two or more strings

  • match()    Use The regular expression pattern performs a search on a string and returns the result containing the search result

  • replace()    Replaces a substring that matches the regular expression

  • search()     Retrieve substrings in a string that match a regular expression. If no match is found, -1 is returned.

  • slice(start, end) Intercept the substring according to the following table

  • substring(start, end) Intercept the substring according to the following table

  • ##split() Split the string into multiple substrings according to the specified delimiter and return the element group
  • substr( start, length)  Truncate the string according to its length

  • toUpperCase()     Return a string in which all letters in the string are converted to uppercase letters.

  • toLowerCase() Returns a string in which all letters are converted to lowercase letters.

  • Methods of Math object

  • ceil()  Round up.

floor()  Round down.

  • round()  Rounding.

  • random() Get a random number.

  • Methods of Date object

  • getDate function: Returns the "day" part of the date, with values ranging from 1 to 31.

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

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

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

  • getMonth function: Returns the "month" part of the date, with values ranging from 0 to 11.

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

  • getTime function: Returns the system time.

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

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

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

  • setDate function: Set date The "day" part has a value of 0 to 31.

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

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

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

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

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

  • setYear function: Set the "year" part of the date.

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

  • setLocaleString function: Convert the date into a string, which is the local time.

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

For more programming-related knowledge, please visit:

Programming Video! !

The above is the detailed content of What are the common methods of JavaScript built-in objects?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!