乐趣区

关于javascript: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
退出移动版