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

How to test if string ends with a list of string

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

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 !");
}

Array.prototype.some()怎么样?

if (strings.some(s => 'hi, this is a test'.endsWith(s))) {...}