Add numbers to strings

JavaScript uses the + operator for both addition and concatenation. Numbers are added. Strings are cascaded.

Numeric string operation

Strings are cascaded using the + operator.

Numeric and non-numeric string operations

digital

Infinity

The value returned by JavaScript when counting outside the maximum possible range.

Values can be objects

Objects can be defined by the keyword new. Creating numeric objects with new slows down execution.

toFixed

Returns a string value containing the number of specified decimal digits, rounded.

toPrecision

Returns a string value containing a number of specified length.

valueOf

Returns a value as a value. All JavaScript data types have valueOf() and toString() methods.

string

Special characters

The string needs to be quoted. If there is anything else in the string that needs to be quoted, you need to use the escape character \.

code The results of describe
\ ‘ Single quotes
\” Double quotation marks
\ \ \ The backslash

Other escape characters

code The results of
\n A newline
\r enter
\f Change the page
\b backspace
\t Horizontal TAB character
\v Vertical TAB character
Strings can be objects

Find string

The indexOf() method returns the index (position) of the first occurrence of the specified text in the string. The lastIndexOf() method returns the index of the last occurrence of the specified text in the string; Two parameters, and the second parameter is retrieved from somewhere. If no text is found, -1 is returned.

Retrieve string

The search() method searches the string for a particular value and returns the matching position.

IndexOf () is equal to search(). The difference between:

  • The search() method cannot set the second start position parameter
  • IndexOf () method does not set more powerful search values (regular expressions)
Extract string

Slice extracts a portion of a string, counting at the end when the argument is negative

Substring (start position, end position) is similar to the slice () method, but the substring() argument cannot accept negative numbers. Substr (start position, length) is similar to slice(). But the length of substr() in the second argument; If the second argument is omitted, the string from the start position to the end position is intercepted.

CharAt (position) returns the character corresponding to the subscript of the string. Returns an empty string if not found. CharCodeAt (position) returns the Unicode of the character corresponding to the string subscript.

Attribute access [], return undefined if not found

Substitution string

The replace(replaced string, new string) method replaces the value specified in the string with another value.

Convert to uppercase and lowercase

ToUpperCase () is converted toUpperCase. ToLowerCase () is converted toLowerCase

concat()

Concat () Connection string.

trim()

Trim () Clears Spaces before and after strings.

String to array

Split, which converts a string to an array.