EN
JavaScript - String endsWith() method example
3 points
The method checks if string ends with some text.
xxxxxxxxxx
1
const text = 'ABC';
2
3
console.log(text.endsWith('C')); // true
4
console.log(text.endsWith('BC')); // true
Syntax |
|
Typed syntax | String endsWith(searchString: string, endPosition?: number): boolean |
Parameters |
|
Result | Returns true if the given text was found at the end of the string, otherwise returns false . |
Description |
The
|
xxxxxxxxxx
1
const text = 'Some text ...';
2
3
console.log(text.endsWith('...')); // true
4
console.log(text.endsWith('text ...')); // true
5
6
console.log(text.endsWith('Some')); // false
7
console.log(text.endsWith('Some text')); // false
xxxxxxxxxx
1
// endPosition: 4 9
2
// | |
3
// v v
4
const text = 'Some text ...';
5
6
console.log(text.endsWith('Some', 4)); // true
7
console.log(text.endsWith('text', 9)); // true
8
console.log(text.endsWith('Some', 9)); // false // 'Some text' doesn't end with 'Some'
9
10
console.log(text.endsWith('text ...', text.length)); // true