JavaScript learning notes: built in API

Time:2021-9-12

This article was updated on September 10, 2020.

Note: in the following, uppercase is a user-defined variable (except for individual uppercase types), which shall be filled in according to the actual situation. use<>Indicates that the content is optional,|Indicates that the left or right content is used,...Indicates that the previous content is repeated.

This article only describes the use briefly. For more detailed use, please refer to the MDN document:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects

catalogue

Global objects are sorted in dictionary order. The attributes of global objects are sorted in this way first: static attributes (such asNumber.MAX_VALUE). instance properties (e.gARRAY.length)Static methods (e.gDate.now). prototype method (e.gArray.prototype.concat); The attributes of the same category are sorted in dictionary order.

The API standard described in this paper is ECMAScript 5.

The following interfaces are deprecated:

  • escape
  • unescape

arguments

The argument of the function where arguments is located is a class array object, which is only defined in the function body.

arguments.callee

The function where arguments is located.

arguments.length

The number of arguments to the function where arguments is located.

Array

Array type.

var ARRAY = new Array();
var ARRAY = new Array(LENGTH);
var ARRAY = new Array(ELEMENT );

ARRAY.length

Number of array elements. Writeable properties.

Array.prototype.concat

Splice arrays.

var NEW_ARRAY = ARRAY.concat(ELEMENT );

Array.prototype.every

Determines whether all elements satisfy the assertion.

var OK = ARRAY.every(
	function(ELEMENT, I, ARRAY) {
		return true;
	}
	
);

This is the point of this when calling the assertion function, the same below.

Array.prototype.filter

Produces a new array using elements that are asserted.

var NEW_ARRAY = ARRAY.filter(
	function(ELEMENT, I, ARRAY) {
		return true;
	}
	
);

Array.prototype.forEach

Call a function for each element.

ARRAY.forEach(
	function(ELEMENT, I, ARRAY) {
	}
	
);

Array.prototype.indexOf

Forward lookup element. Use = = = to judge equality. If it does not exist, it returns – 1.

var INDEX = ARRAY.indexOf(VALUE );

Array.prototype.join

Concatenate arrays into strings.

var STR = ARRAY.join();

The default value of separator is “,”.

Array.prototype.lastIndexOf

Reverse lookup element. Use = = = to judge equality. If it does not exist, it returns – 1.

var INDEX = ARRAY.lastIndexOf(VALUE, );

Array.prototype.map

Calculate the new array.

var NEW_ARRAY = ARRAY.map({
	function(ELEMENT, I, ARRAY) {
		return VALUE;
	}
	
});

Array.prototype.pop

Removes and returns the last element.

var ELEMENT = ARRAY.pop();

Array.prototype.push

Appends an element to the end of the array.

var LENGTH = ARRAY.PUSH(ELEMENT );

Array.prototype.reduce

Calculates a value from the forward direction of the array.

var VALUE = ARRAY.reduce(
	function(RESULT1, ELEMENT, I, ARRAY) {
		return RESULT2;
	}
	
);

If initial is specified, initial and the first element of the array will be passed in the first call of the function parameter; Otherwise, the first and second elements are passed in the first call of the function parameter.

Array.prototype.reduceRight

Calculates a value inversely from the array.

var VALUE = ARRAY.reduceRight(
	function(RESULT1, ELEMENT, I, ARRAY) {
		return RESULT2;
	}
	
);

If initial is specified, initial and the last element of the array will be passed in the first call of the function parameter; Otherwise, the last and penultimate elements are passed in the first call of the function parameter.

Array.prototype.reverse

Invert array elements.

ARRAY.reverse();

Array.prototype.shift

Removes and returns the first element.

var ELEMENT = ARRAY.shift();

Array.prototype.slice

Use a part of the array to generate a new array.

var NEW_ARRAY = ARRAY.slice(START_INDEX );

The range of array corresponding to the new array is [start_index, end_index]. Both start_index and end_index can be negative numbers, indicating that – 1 is the last element from the tail number.

Array.prototype.some

Determine whether any element satisfies the assertion.

var OK = ARRAY.some(
	function(ELEMENT, I, ARRAY) {
		return true;
	}
	
);

Array.prototype.sort

Sort the array.

var ARRAY = ARRAY.sort(
	
);

If the function parameters are not used, the values after the array elements are converted into strings are sorted in dictionary order. If the return value of the function parameter is less than 0, it means element1ELEMENT2。

Array.prototype.splice

Can be used to insert, delete, or replace array elements.

var DELETE_ARRAY = ARRAY.splice(
	START_INDEX,
	DELETE_COUNT
	>
);

Delete start first_ Delete from index (inclusive)_ Count elements, and then start_ Inserts the specified element at index and returns the array of deleted elements.

Array.prototype.toLocaleString

Convert to localized string.

var STR = ARRAY.toLocaleString();

Array.prototype.toString

Convert to string.

var STR = ARRAY.toString();

Return value andARRAY.join()Same.

Array.prototype.unshift

Add elements to the array header.

var LENGTH = ARRAY.unshift(ELEMENT );

Boolean

Boolean type.

var BOOLEAN = new Boolean(VALUE);
var BOOLEAN = Boolean(VALUE);

Boolean.prototype.toString

Convert to string.

var STR = BOOLEAN.toString();

Returns “true” or “false”.

Boolean.prototype.valueOf

Returns the original Boolean value.

var BOOL = BOOLEAN.valueOf();

Date

Date time type.

var DATE = new Date(MILLISECONDS);
var DATE = new Date();
var DATE = new Date(STR);
var DATE = new Date(YEAR, MONTH >>>>);
var STR = Date();

When milliseconds is passed in, it is the local time corresponding to UTC time after a specified number of milliseconds from zero on January 1, 1970. Other calls are local time specified by the parameter.

The most complete format of STR is: 2006-01-02t15:04:05.000z.

Month is 0 to 11, datelength is 1 to 31, hour is 0 to 23, minute is 0 to 59, second is 0 to 59, millisecond is 0 to 999.

The following interfaces are deprecated:

  • Date.prototype.getYear
  • Date.prototype.setYear
  • Date.prototype.toGMTString

Date.now

Returns the number of milliseconds elapsed in UTC from 0:00 on January 1, 1970 to the present UTC time.

var MILLISECONDS = Date.now();

Date.parse

Parse date time from string.

var DATE = Date.parse(STR);

The most complete format of string is: 2006-01-02t15:04:05.000z.

Date.UTC

Returns the number of milliseconds elapsed from 0:00 on January 1, 1970 to the current UTC time specified by the parameter.

var MILLISECONDS = Date.UTC(YEAR, MONTH >>>>)

Date.prototype.getDate

Returns the day of local time.

var DATE_IN_MONTH = DATE.getDate();

Date.prototype.getDay

Returns the week of the local time.

var DAY = DATE.getDay();

The return values are 0 (Sunday) to 6 (Saturday).

Date.prototype.getFullYear

Returns the year of the local time.

var YEAR = DATE.getFullYear();

Date.prototype.getHours

When the local time is returned.

var HOUR = DATE.getHours();

Date.prototype.getMilliseconds

Returns the milliseconds of the local time.

VAR MILLISECOND = DATE.getMilliseconds();

Date.prototype.getMinutes

Returns the minutes of local time.

var MINUTE = DATE.getMinutes();

Date.prototype.getMonth

Returns the month of the local time.

var MONTH = DATE.getMonth();

Date.prototype.getSeconds

Returns the second of the local time.

var SECOND = DATE.getSeconds();

Date.prototype.getTime

Returns the number of milliseconds elapsed from 0:00 UTC time on January 1, 1970 for the corresponding UTC time.

var MILLISECONDS = DATE.getTime();

Date.prototype.getTimezoneOffset

Returns the time difference between the local time zone and the UTC time zone, expressed in minutes.

var MINUTES = DATE.getTimezoneOffset();

Date.prototype.getUTCDate

Returns the day of UTC time.

var DATE_IN_MONTH = DATE.getUTCDate();

Date.prototype.getUTCDay

Returns the week of UTC time.

var DAY = DATE.getUTCDay();

The return values are 0 (Sunday) to 6 (Saturday).

Date.prototype.getUTCFullYear

Returns the year of UTC time.

var YEAR = DATE.getUTCFullYear();

Date.prototype.getUTCHours

When the UTC time is returned.

var HOUR = DATE.getUTCHours();

Date.prototype.getUTCMilliseconds

Returns the milliseconds of UTC time.

VAR MILLISECOND = DATE.getUTCMilliseconds();

Date.prototype.getUTCMinutes

Returns the minutes of UTC time.

var MINUTE = DATE.getUTCMinutes();

Date.prototype.getUTCMonth

Returns the month of UTC time.

var MONTH = DATE.getUTCMonth();

Date.prototype.getUTCSeconds

Returns the second of UTC time.

var SECOND = DATE.getUTCSeconds();

Date.prtotype.setDate

Sets the day of the local time.

var MILLISECONDS = DATE.setDate(DATE_IN_MONTH);

Returns the number of milliseconds since the UTC time was set on January 1, 1970. The same below.

Date.prototype.setFullYear

Set the year, month and day of the local time.

var MILLISECONDS = DATE.setFullYear(YEAR >);

Date.prototype.setHours

Set the hour, minute, second and millisecond of local time.

var MILLISECONDS = DATE.setHours(HOUR >>);

Date.prototype.setMilliseconds

Sets the milliseconds of the local time.

var MILLISECONDS = DATE.setMilliseconds(MILLISECOND);

Date.prototype.setMinutes

Set the minutes, seconds and milliseconds of the local time.

var MILLISECONDS = DATE.setMinutes(MINUTE >);

Date.prototype.setMonth

Set the month and day of local time.

var MILLISECONDS = DATE.setMonth(MONTH );

Date.prototype.setSeconds

Set the seconds and milliseconds of the local time.

var MILLISECONDS = DATE.setSeconds(SECOND );

Date.prototype.setTime

Set the time to UTC. The specified number of milliseconds elapsed from zero on January 1, 1970.

var MILLISECONDS = DATE.setTime(MILLISECONDS);

Date.prtotype.setUTCDate

Sets the day of UTC time.

var MILLISECONDS = DATE.setUTCDate(DATE_IN_MONTH);

Returns the number of milliseconds since the UTC time was set on January 1, 1970. The same below.

Date.prototype.setUTCFullYear

Set year, month and day of UTC time.

var MILLISECONDS = DATE.setUTCFullYear(YEAR >);

Date.prototype.setUTCHours

Set the hour, minute, second and millisecond of UTC time.

var MILLISECONDS = DATE.setUTCHours(HOUR >>);

Date.prototype.setUTCMilliseconds

Sets the milliseconds of UTC time.

var MILLISECONDS = DATE.setUTCMilliseconds(MILLISECOND);

Date.prototype.setUTCMinutes

Set the minutes, seconds and milliseconds of UTC time.

var MILLISECONDS = DATE.setUTCMinutes(MINUTE >);

Date.prototype.setUTCMonth

Set the month and day of UTC time.

var MILLISECONDS = DATE.setUTCMonth(MONTH );

Date.prototype.setUTCSeconds

Set the seconds and milliseconds of UTC time.

var MILLISECONDS = DATE.setUTCSeconds(SECOND );

Date.prototype.toDateString

Returns the date string of the local time, which is related to the implementation, such as Tue Jul 07 2020.

var STR = DATE.toDateString();

Date.prototype.toISOString

Returns the date time string of UTC time, using iso-8601 standard, such as 2020-07-07t15:56:14.306z.

var STR = DATE.toISOString();

Date.prototype.toJSON

Returns the date time string of UTC time, using iso-8601 standard, such as 2020-07-07t15:56:14.306z.

var STR = DATE.toJSON();

The parameter key is ignored.

Date.prototype.toLocaleDateString

Returns the date string of local time and local custom, which is related to the implementation, such as 2020 / 7 / 7.

var STR = DATE.toLocaleDateString();

Date.prototype.toLocaleString

Returns the date time string of local time and local custom, which is related to the implementation, such as 11:56:14 p.m. on July 7, 2020.

var STR = DATE.toLocaleString();

Date.prototype.toLocaleTimeString

Returns the time string of local time and local custom, which is related to the implementation, such as 11:56:14 p.m.

var STR = DATE.toLocaleTimeString();

Date.prototype.toString

Returns the date time string of the local time, which is related to the implementation, such as Tue Jul 07 2020 23:56:14 GMT + 0800 (China standard time).

var STR = DATE.toString();

Date.prototype.toTimeString

Returns the time string of local time, which is related to the implementation, such as 23:56:14 GMT + 0800 (Chinese standard time).

var STR = DATE.toTimeString();

Date.prototype.toUTCString

Returns the date time string of UTC time, which is related to implementation, such as Tue, 07 Jul 2020 15:56:14 GMT.

var STR = DATE.toUTCString();

Date.prototype.valueOf

Returns the number of milliseconds elapsed from 0:00 UTC time on January 1, 1970 for the corresponding UTC time.

var MILLISECONDS = DATE.valueOf();

decodeURI

Decode the URI to decode the hexadecimal escape sequence starting with% into the characters it represents. Inverse operation of encodeuri.

var URI_DECODED = decodeURI(URI);

decodeURIComponent

The component that decodes the URI decodes the hexadecimal escape sequence starting with% into the characters it represents. Inverse operation of encodeuricomponent.

var COMPONENT_DECODED = decodeURIComponent(COMPONENT);

encodeURI

Encoding URI. Add letters, numbers, -! ~ * ‘ () and; /? & = + $# Characters other than are encoded as hexadecimal escape sequences starting with%. Characters used to separate URI components will not be escaped.

var URI_ENCODED = encodeURI(URI);

encodeURIComponent

Encode the URI component. Add letters, numbers and -.! ~ * ‘ Characters other than () are encoded as hexadecimal escape sequences starting with%, which will escape those characters used to separate URI components.

var COMPONENT_ENCODED = encodeURIComponent(COMPONENT);

Error

Error type.

var ERROR = new Error();

ERROR.message

Error message.

ERROR.name

The name of the constructor that created the error instance.

Error.prototype.toString

Convert to string.

var STR = ERROR.toString();

eval

Execute JavaScript code and return the evaluation result of the executed code.

var RETURN = eval(STR);

EvalError

The error type of the execution code error.

var EVALERROR = new EvalError();

EVALERROR.message

Error message.

EVALERROR.name

The name of the constructor that created the error instance, that is, evalerror.

Function

Function type.

var FUNCTION = new Function(STR_PARAM_NAME  STR_BODY);

The following interfaces are deprecated:

  • FUNCTION.arguments
  • FUNCTION.caller

FUNCTION.length

Number of formal parameters.

FUNCTION.prototype

Prototype object. When function is used as a constructor, the created object will inherit the properties and methods of the prototype object.

Function.prototype.apply

Call a function as a method of an object.

var RETURN = FUNCTION.apply(THIS );

Function.prototype.bind

Bind the function as a method of an object to generate a new function.

var FUNCTION_BOUND = FUNCTION.bind(THIS >);

Function.prototype.call

Call a function as a method of an object.

var RETURN = FUNCTION.call(THIS >);

Function.prototype.toString

Convert to string.

var STR = FUNCTION.toString();

Infinity

Infinity.

isFinite

Whether it is a finite number.

var OK = isFinite(NUM);

isNaN

Non numeric.

var OK = isNaN(VALUE);

JSON

JSON serializes and deserializes objects.

JSON.parse

Deserialize the string to the original value.

var DATA = JSON.parse(
	STR
	
);

If the return value of the function parameter is undefined, the attribute key is removed_ OR_ INDEX。

JSON.stringify

Serializes the original value as a string.

var STR = JSON.stringify(
	DATA
	
	>
);

If the return value of the function parameter is undefined, the attribute key is not_ OR_ Index is serialized.

Only the first 10 characters of index are indented in each line, or n spaces are used as indent when 1 < = n < = 10.

Math

Mathematical objects.

Math.E

e. The approximate value is 2.71828.

Math.LN10

Ln (10), approximately 2.30259.

Math.LN2

Ln (2), approximately 0.69315.

Math.LOG10E

LG (E), approximately 0.43429.

Math.LOG2E

Log2 (E), approximately 1.44270.

Math.PI

π. The approximate value is 3.14159.

Math.SQRT1_2

1 / √ 2, approximate value is 0.70711.

Math.SQRT2

√ 2, approximate value is 1.41421.

Math.abs

Absolute value.

var RESULT = Math.abs(VALUE);

Math.acos

Inverse cosine value, resulting in radians.

var RESULT = Math.acos(VALUE);

Math.asin

Inverse sine, resulting in radians.

var RESULT = Math.asin(VALUE);

Math.atan

Arctangent, resulting in radians.

var RESULT = Math.atan(VALUE);

Math.atan2

Radian from the X axis to the specified point.

var RESULT = Math.atan2(Y, X);

Equivalent toMath.atan(Y/X)

Math.ceil

Round up.

var RESULT = Math.ceil(VALUE);

Math.cos

Cosine value, the parameter is radian.

var RESULT = Math.cos(VALUE);

Math.exp

E to the power of value.

var RESULT = Math.exp(VALUE);

Math.floor

Round down.

var RESULT = Math.floor(VALUE);

Math.log

ln(VALUE)。

var RESULT = Math.log(VALUE);

Math.max

Maximum value.

var RESULT = Math.max(VALUE );

Math.min

Minimum value.

var RESULT = Math.min(VALUE );

Math.pow

The Y power of X.

var RESULT = Math.pow(X, Y);

Math.random

Pseudo random value, interval range [0.0, 1.0).

var RESULT = Math.random();

Math.round

Rounded value.

var RESULT = Math.round(VALUE);

Math.sin

Sine value, the parameter is radian.

var RESULT = Math.sin(VALUE);

Math.sqrt

Square root value.

var RESULT = Math.sqrt(VALUE);

Math.tan

Tangent value, the parameter is radian.

var RESULT = Math.tan(VALUE);

NaN

Non numeric.

Number

Value type.

var NUMBER = new Number(NUM);
var NUMBER = Number(NUM);

Number.MAX_VALUE

The maximum value is approximately 1.79e + 308.

Number.MIN_VALUE

Minimum value, approximate 5e-324.

Number.NaN

Non numeric, equivalent toNaN

Number.NEGATIVE_INFINITY

Negative infinity is equal to-Infinity

Number.POSITIVE_INFINITY

Positive infinity is equal toInfinity

Number.prototype.toExponential

Returns a string represented by exponential notation.

var STR = NUMBER.toExponential();

Number.prototype.toFixed

Returns a string represented by fixed-point notation.

var STR = NUMBER.toFixed();

Number.prototype.toLocaleString

Returns a string in local format.

var STR = NUMBER.toLocaleString();

Number.prototype.toPrecision

Returns a string with a valid number of the specified precision.

var STR = NUMBER.toPrecision();

Number.prototype.toString

Returns a string in the specified hexadecimal representation.

var STR = NUMBER.toString();

Number.prototype.valueOf

Returns the original numeric value.

var NUM = NUMBER.valueOf();

Object

Object type.

var OBJECT = new Object();

OBJECT.constructor

Object.

Object.create

Creates an object using the specified prototype and properties.

var OBJECT = Object.create(
	PROTO
	
			
			
			
			
			
		}
		
	}>
);

The meanings of the fields of the attribute description object are as follows (the same below):

  • Value: attribute value. The data property has this field.
  • Writable: whether the property is writable. The data property has this field.
  • Enumerable: whether the property is enumerable. Both data properties and accessor properties have this field.
  • Configurable: whether the attribute is configurable, that is, whether the description object of the attribute can be configured and whether the attribute can be deleted. Both data properties and accessor properties have this field.
  • Get: property accessor getter. Accessor properties have this field.
  • Set: the property accesses its setter. Accessor properties have this field.

Object.defineProperties

Defines multiple properties of an object.

var OBJECT = Object.defineProperties(
	OBJECT
	
			
			
			
			
			
		}
		
	}>
);

Object.defineProperty

Defines a property of an object.

var OBJECT = Object.defineProperty(
	OBJECT
	, KEY
	
		
		
		
		
		
	}>
);

Object.freeze

Freeze objects. That is, the object is closed (like object. Seal), and all non inherited properties are set to read-only (writable is false), but the accessor setter property and inheritance property are not affected. This is a permanent irreversible operation.

var OBJECT = Object.freeze(OBJECT);

Object.getOwnPropertyDescriptor

Returns a description object of a non inherited property.

/*
{
	
	
	, enumerable: BOOL
	, configurable: BOOL
	
	
}
*/
var DESCRIPTOR = Object.getOwnPropertyDescriptor(OBJECT, KEY);

Object.getOwnPropertyNames

Returns the names of all non inherited properties of the object, including non enumerable properties.

var KEY_ARRAY = Object.getOwnPropertyNames(OBJECT);

Object.getPrototypeOf

Returns the prototype of the object.

var PROTO = Object.getPrototypeOf(OBJECT);

Object.isExtensible

Check whether the object is extensible. Extensible to add new non inherited properties.

var OK = Object.isExtensible(OBJECT);

Object.isFrozen

Check whether the object is frozen. Frozen is closed, and all non inherited properties are read-only (writable is false).

var OK = Object.isFrozen(OBJECT);

Object.isSealed

Check whether the object is enclosed. Closed, that is, new non inherited attributes (non extensible) cannot be added, and existing non inherited attributes cannot be configured (configurable is false).

var OK = Object.isSealed(OBJECT);

Object.keys

Returns all non inheritable enumerable property names of an object.

var KEY_ARRAY = Object.keys(OBJECT);

Object.preventExtensions

Make the object non extensible. That is, you cannot add new non inherited attributes, but the inherited attributes are not affected. This is a permanent irreversible operation.

var OBJECT = Object.preventExtensions(OBJECT);

Object.seal

Enclose objects. That is, new non inherited attributes (non extensible) cannot be added, and the existing non inherited attributes are set to non configurable (configurable is false), but the inherited attributes are not affected. This is a permanent irreversible operation.

var OBJECT = Object.seal(OBJECT);

Object.prototype.hasOwnProperty

Check whether the property is non inherited.

var OK = OBJECT.hasOwnProperty(KEY);

Object.prototype.isPrototypeOf

Checks whether the current object is a prototype of another object.

var OK = OBJECT.isPrototypeOf(OTHER_OBJECT);

Object.prototype.propertyIsEnumerable

Check whether the property is non inheritable and enumerable.

var OK = OBJECT.propertyIsEnumerable(KEY);

Object.prototype.toLocaleString

Returns a string in local format.

var STR = OBJECT.toLocaleString();

Object.prototype.toString

Convert to string.

var STR = OBJECT.toString();

Object.prototype.valueOf

Returns the original value of the object. If not, the object itself is returned.

var VALUE = OBJECT.valueOf();

parseFloat

Parses a string to a floating point number. When a valid character that is not a floating point number is encountered, the parsing will terminate and return the parsed value, possiblyNaN

var FLOAT = parseFloat(STR);

parseInt

Parses a string to an integer. When a valid character that is not an integer is encountered, the parsing will terminate and return the parsed value, possiblyNaN

var INT = parseInt(STRING );

String can be expressed in hexadecimal in the format of 0x or 0x.

RangeError

Error types with values outside the legal range, including array subscript out of bounds.

var RANGEERROR = new RangeError();

RANGEERROR.message

Error message.

RANGEERROR.name

The name of the constructor that created the error instance, i.e. rangeerror.

ReferenceError

Wrong type to reference a variable that does not exist.

var REFERENCEERROR = new ReferenceError();

REFERENCEERROR.message

Error message.

REFERENCEERROR.name

The name of the constructor that created the error instance, i.e. referenceerror.

RegExp

Regular expression type.

var REGEXP = new RegExp(PATTERN );

The literal corresponding to the return value is/PATTERN/ATTRIBUTES。 Attributes can be any combination of G (global matching, i.e. finding all matches instead of stopping when the first one is found), I (ignoring case matching), m (multi line matching, i.e. ^ matches not only the beginning of the string but also the beginning of the line, and $matches not only the end of the string but also the end of the line).

REGEXP.global

Whether it is a global match, that is, whether there is a G modifier.

REGEXP.ignoreCase

Whether case matching is ignored, i.e. whether there is an I modifier.

REGEXP.lastIndex

The starting subscript of the next string match.

Used for global matching. When no match is found in regexp.exec or regexp.test, the value will be automatically set to 0; When a match is found, the value is set as the subscript of the first character after the match to allow repeated calls to traverse all matches. If you need to search for a new string again after finding a match, you need to explicitly set the value to 0.

REGEXP.multiline

Whether it is a multiline match, that is, whether there is an M modifier.

REGEXP.source

The corresponding source text, that is, pattern.

RegExp.prototype.exec

General pattern matching.

/*
[
	MATCHED_STR
	>,
	index: BEGIN_INDEX_OF_MATCHED_STR,
	input: STR
]
*/
var ARRAY = REGEXP.exec(STR);

If a match is found, an array is returned: the first element matched_ STR is the string in str that matches the regular expression, followed by the element matched_ STR_ OF_ Group is matched_ STR is the string that matches each group of regular expression (caused by “()”), and the index is matched_ The first character of STR is the subscript in str, and the input is the parameter of regexp.exec, that is, str. If no match is found, null is returned.

RegExp.prototype.test

Test whether the string matches.

var OK = REGEXP.test(STR);

RegExp.prototype.toString

Convert to string.

var STR = REGEXP.toString();

The returned string is the same as the literal form / pattern / attributes, and may contain escape characters.

String

String type.

var STRING = new String(STR);

The following interfaces are deprecated:

  • String.prototype.substr

STRING.length

Number of string characters. Read only property.

String.fromCharCode

Creates a string using Unicode encoding.

var STR = String.fromCharCode(CODE );

String.prototype.charAt

Returns the nth character. If the subscript is out of bounds, an empty string is returned.

var STR = STRING.charAt(N);

String.prototype.charCodeAt

Returns the Unicode encoding of the nth character, which is a 16 bit integer. Nan is returned if the subscript is out of bounds.

var CODE = STRING.charCodeAt(N);

String.prototype.concat

Splice string.

var NEW_STR = STRING.concat(STR );

String.prototype.indexOf

Forward lookup string. Returns the subscript of the first character of the substring in the original string. If it does not exist, it returns – 1.

var INDEX = STRING.indexOf(SUB_STR );

String.prototype.lastIndexOf

Reverse lookup string. Returns the subscript of the first character of the substring in the original string. If it does not exist, it returns – 1.

var INDEX = STRING.lastIndexOf(SUB_STR );

String.prototype.localeCompare

Compare strings using local rules. This function takes advantage of the sorting provided by the operating system.

var RESULT = STRING.localeCompare(OTHER_STR);

If the return value is less than 0, it means stringOTHER_STR。

String.prototype.match

Search for matching substrings.

//When regexp is a global match:
/*
[MATCHED_STR ]
*/
//When regexp is not a global match:
/*
[
	MATCHED_STR
	>,
	index: BEGIN_INDEX_OF_MATCHED_STR,
	input: STRING
]
*/
var ARRAY = STRING.match(REGEXP);

When regexp is a global match, if a match is found, an array is returned: each element matched_ STR is the string in string that matches the regular expression. If no match is found, null is returned.

When regexp is not a global match, if a match is found, an array is returned: the first element matched_ STR is the string in string that matches the regular expression, followed by the element matched_ STR_ OF_ Group is matched_ STR is the string that matches each group of regular expression (caused by “()”), and the index is matched_ The subscript of the first character of STR in string. Input is string. If no match is found, null is returned.

String.prototype.replace

Replace the matching substring.

var STR_REPLACED = STRING.replace(
	STR|REGEXP,
	REPLACEMENT_STR|function(MATCHED_STR >, BEGIN_INDEX_OF_MATCHED_STR, STRING) {
		return REPLACEMENT_STR;
	}
);

When regexp is a global match, replace all matching substrings. Otherwise, only the first matching substring is replaced.

REPLACEMENT_ The “$” in str has special meaning:

  • $n: the string in the matched substring that matches the nth grouping of the regular expression (caused by “()”.
  • $&: matching substrings.
  • $`: the string to the left of the matching substring.
  • $’: the string to the right of the matching substring.
  • $$$: $symbol itself.

Among the parameters of function parameters, the first parameter is matched_ STR is the string in string that matches the regular expression, followed by the parameter matched_ STR_ OF_ Group is matched_ STR string that matches each grouping of regular expression (caused by “()”), begin_ INDEX_ OF_ MATCHED_ STR is matched_ The subscript of the first character of STR in string, which is the string object itself.

String.prototype.search

Find matching substrings.

var INDEX = STRING.search(REGEXP);

Returns the subscript of the first character of the first matching substring in the string, or – 1 if it does not exist. Always search from scratch without global matching, that is, ignore the G modifier and lastindex attribute.

String.prototype.slice

Generates a new string using a portion of the string.

var NEW_STR = STRING.slice(START_INDEX );

The range of string corresponding to the new string is [start_index, end_index]. Both start_index and end_index can be negative numbers, indicating that – 1 is the last element from the tail number.

String.prototype.split

Cut the string into an array.

var ARRAY = STRING.split(>);

If no separation rule is specified, an array containing only one element of the string itself is returned.

If the separation rule is an empty string, the returned array takes each character of the string as an element.

If the separation rule matches the content at the beginning of the string, the first element is an empty string; If the separation rule matches the content at the end of the string, the last element is an empty string. (except when the separation rule is an empty string.)

If the separation rule is a regular expression with grouping (caused by “()”), the substrings matching the grouping are also included in the array.

String.prototype.substring

Returns a substring.

var NEW_STR = STRING.substring(START_INDEX );

The range of string corresponding to the new string is [start_index, end_index]. Both start_index and end_index cannot be negative numbers.

String.prototype.toLocaleLowerCase

Convert to lowercase string in local format.

var NEW_STR = STRING.toLocaleLowerCase();

String.prototype.toLocaleUpperCase

String converted to local uppercase format.

var NEW_STR = STRING.toLocaleUpperCase();

String.prototype.toLowerCase

Convert to lowercase string.

var NEW_STR = STRING.toLowerCase();

String.prototype.toString

Returns the original string value.

var STR = STRING.toString();

String.prototype.toUpperCase

Convert to uppercase string.

var NEW_STR = STRING.toUpperCase();

String.prototype.trim

Remove white space at the beginning and end.

var NEW_STR = STRING.trim();

String.prototype.valueOf

Returns the original string value.

var STR = STRING.valueOf();

SyntaxError

Error type of syntax error.

var SYNTAXERROR = new SyntaxError();

SYNTAXERROR.message

Error message.

SYNTAXERROR.name

The name of the constructor that created the error instance, syntaxerror.

TypeError

Wrong type of value.

var TYPEERROR = new TypeError();

TypeError.message

Error message.

TypeError.name

The name of the constructor that created the error instance, i.e. typeerror.

undefined

No value defined.

Undefined is not a constant and can be set to other values, but you must be very careful.

URIError

Error type of URI encoding or decoding error.

var URIERROR = new URIError();

URIError.message

Error message.

URIError.name

The name of the constructor that created the error instance, namely: urierror.