PHP Learning Notes (a common method in JS)

Source: Internet
Author: User
Tags mathematical functions square root

Common methods in JS:

1. Date-time function (requires variable invocation):
var B = new Date (); Get current time
B.gettime ()//Get timestamp
B.getfullyear ()//Get Year
B.getmonth (+1); Get month
B.getdate ()//Get Day
B.gethours ()//Get Hours
B.getminutes ()//Get minutes
B.getseconds ()//Get the number of seconds
B.getday ()//Get the day of the week
B.getmilliseconds ()//Get milliseconds
Date ()//Get full date


2. Mathematical functions (called with math):
ABS (x) The absolute value of the return number.
Ceil (x) is rounded on the logarithm.
Floor (x) is rounded down with a logarithmic.
Round (x) rounds the number to the nearest integer.
Max (x, y) returns the highest value in X and Y.
Min (x, y) returns the lowest value in X and Y.
The POW (x, y) returns the y power of X.
SQRT (x) returns the square root of the number.
Random () returns an arbitrary number between 0 and 1. ****

String functions (called with variables):

IndexOf
Returns the index (from left to right) of the first occurrence of a substring in a string. If there is no match, returns-1.
var index1 = A.indexof ("L");
INDEX1 = 2

CharAt returns the character at the specified position.

var Get_char = A.charat (0);
Get_char = "H"

L Astindexof
Returns the index (right-to-left search) at the last occurrence of a substring in a string, or 1 if there are no matches.
var index1 = lastIndexOf (' l ');
INDEX1 = 3


Match
Checks if a string matches the contents of a regular expression, and returns null if there is a match.
var re = new RegExp (/^\w+$/);
var is_alpha1 = A.match (re);
IS_ALPHA1 = "Hello"
var is_alpha2 = B.match (re);
IS_ALPHA2 = null

Substring
Returns a substring of a string in which the incoming parameter is the starting and ending position.

var sub_string2 = a.substring (1,4);
Sub_string2 = "ell"

SUBSTR ********
Returns a substring of a string in which the incoming parameter is the starting position and length
var sub_string1 = a.substr (1);
Sub_string1 = "Ello"
var sub_string2 = a.substr (1,4);
Sub_string2 = "Ello"

Replace *******
Replace String, the first argument represents the replaced string, the second argument represents the replacement string
A.replace ("he", "AA")


Search
Performs a regular expression matching lookup. If the lookup succeeds, returns the matching index value in the string. otherwise returns-1.
var index1 = A.search (re);
index1 = 0
var index2 = B.search (re);
Index2 =-1

Split ******
A string is made into a string array by dividing the string into substrings.
var arr1 = A.split ("");
ARR1 = [H,e,l,l,o]

Length property *******
Returns the length of a string, which refers to the number of characters it contains.


toLowerCase
Turns the entire string into lowercase letters.
var lower_string = A.tolowercase ();
lower_string = "Hello"

toUpperCase
Turns the entire string into uppercase.
var upper_string = A.touppercase ();
upper_string = "HELLO"

PHP Learning Notes (a common method in JS)

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.