Article From:https://www.cnblogs.com/ycg-myblog/p/9906444.html

## 2、includes(), startsWith(), endsWith()

• includes()：Returns a Boolean value indicating whether a parameter string has been 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
```let s = 'Hello world!';

s.startsWith('Hello') // true
s.endsWith('!') // true
s.includes('o') // true```

All three methods support the second parameter, which indicates where the search begins.

```let s = 'Hello world!';

s.startsWith('world', 6) // true
s.endsWith('Hello', 5) // true
s.includes('Hello', 6) // false```

The code above indicates that the second parameter is used`n`At that time,`endsWith`Behavior differs from the other two approaches. It aims at the front.`n`Two characters, while the other two methods are for the following`n`One position until the end of the string.

## 3、repeat()

`repeat`Method returns a new string to repeat the original string`n`Second time.

```'x'.repeat(3) // "xxx"
'na'.repeat(0) // ""
'na'.repeat(2.9) // "nana" Decimals are rounded down//If the parameter of repeat is negative or Infinity, an error will be reported.
'na'.repeat(Infinity)
// RangeError
'na'.repeat(-1)
// RangeError```

However, if the parameter is a decimal between 0 and – 1, it is equal to 0, because the integer operation is performed first. The decimal number between 0 and – 1, when taken as an integral, equals`-0``repeat`See as 0.

```'na'.repeat(-0.9) // ""
'na'.repeat(NaN) // ""        NaNEqual to 0
'na'.repeat(true) // "na"     tureEqual to 1
'na'.repeat(false) // ""      tureEqual to 0
'na'.repeat('2') //"nana"     Strings are converted to numbers first```

ES2017 The function of string completion length is introduced. If a string is not long enough, it will be filled in at the head or tail.`padStart()`For head repair,`padEnd()`For tail repair.

```//The original string length is less than the specified length

//The original string length is longer than the specified length

If the length of the complement string exceeds the specified minimum length of the original string, the complement string that exceeds the number of digits is truncated.

```'abc'.padStart(10, '0123456789')
// '0123456abc'```

If the second parameter is omitted, the blank completion length is used by default.

```'x'.padStart(4) // '   x'
Embedding variables in Template Strings requires that variable names be written in`\${}`In
```\$('#result').append(`There are <b>\${basket.count}</b> items