likes
comments
collection
share

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

作者站长头像
站长
· 阅读数 25
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