ES6 string and numeric expansion

One: String expansion

1. Character Unicode notation

     It is allowed to represent a character in the form of \uxxxx, but this notation is limited to characters whose code points are between \u0000 and \uFFFF, beyond which must be represented in the form of two double bytes.

    Or put in curly brackets to interpret. For example, \u{1F680} has the same effect as \ uD83D\uDE80

2、codePointAt()

  Can correctly handle characters stored in 4 bytes, returning the code point of a character.

  The parameter of the codeointAt() method is the position of the character in the string (starting from 0). The code point returned is in decimal

3、formCodePoint()

   String.formCodePoint() returns the code point to the corresponding character. There can be multiple parameters, and they will be combined into a string for return.

4. String Traverser Interface

    Strings can be for. . . . of loop through

5 at()

  chartAt() returns the character at the given position of the string, cannot identify the character whose code point is greater than 0xFFFF, and returns the character represented by 2 bytes.

  It is currently proposed to use the at() method. Need to introduce third-party js to achieve.

6 includes(),startsWith(),endsWith()

  includes(): returns a boolean value indicating whether the parameter string was found

  startsWith(): returns a boolean value indicating whether the parameter string is at the head of the original string

  endsWith(): Returns a boolean value indicating whether the parameter string is at the end of the original string

  The above three methods all support the second parameter, which indicates the position to start the search.

7. The repeat() method returns a new string, indicating that the original string is repeated n times

 'x'.repeat(3);//xxx

If the parameter is a decimal, it will be rounded up. If it is a decimal between 0 and -1, it is equivalent to 0.

  Argument NaN is equivalent to 0

8. padStart(), padEnd() If the string is not long enough, it will be completed at the head or tail.

 Accepts two parameters, the first parameter is used to specify the minimum length of the string, and the second parameter is used to complete the string.

Two: Numerical expansion

1. Binary and Octal Notation

Binary 0b (0B) Octal 0O (0o)

If you need to convert binary and octal to decimal, just use Number e.g. Number('0b111')//7

2、Number.isFinite(),Number.isNaN()

  isFinite() is used to check whether a value is finite. If the parameter type is not a value, the returned value is always false

isNaN returns true only for NaN, and returns false for the rest;

3、Number.parseInt(),Number.parseFloat()

4、Number.isTnterger

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324977371&siteId=291194637