JS如何判断字符串或数组包含内容?

const array1 = [1, 2, 3];

console.log(array1.includes(2));
// 预期输出: true

const pets = ['cat', 'dog', 'bat'];

console.log(pets.includes('cat'));
// 预期输出: true

console.log(pets.includes('at'));
// 预期输出: false

const string1 = "taeas,wiki"

console.log(string1.includes('taeas'));
// 预期输出: true

你可能感兴趣的:(JS如何判断字符串或数组包含内容?)