如何测试字符串是否以字符串列表结尾

Ayf*_*fri 6 javascript arrays string ends-with

我有一个字符串数组和另一个字符串,有没有一种简单的方法来测试我的单个字符串是否以字符串数组中的一个字符串结尾?

const strings = [
  'foo',
  'bar',
  'test'
];

if ('hi, this is a test'.endsWith(...strings)) { // I know that this isn't right but this is the idea
  console.log("String ends with one of the strings !");
}
Run Code Online (Sandbox Code Playgroud)

Rob*_*bok 9

怎么样Array.prototype.some()

if (strings.some(s => 'hi, this is a test'.endsWith(s))) {...}
Run Code Online (Sandbox Code Playgroud)