The endsWith() method in JavaScript is used to check whether a string ends with the characters of a specified string.

Syntax:

string.endsWith(searchString, length)

Parameters:

  • searchString: Required. The string to search for at the end of the given string.
  • length: Optional. Specifies the length of the string to search within. If not specified, the whole string will be searched.

Return value:

  • Returns true if the given string ends with the specified string, otherwise returns false.

Example:

const str = "Hello World!";

console.log(str.endsWith("World!")); // true
console.log(str.endsWith("world!")); // false - case-sensitive
console.log(str.endsWith("lo", 5)); // true - searches within the first 5 characters
``
Method endWith javascript

原文地址: https://www.cveoy.top/t/topic/g5jh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录