1 回答
TA贡献1854条经验 获得超8个赞
如果您需要检查该项目是否存在于数组中,则只需使用方法:some
let val = ($('#sociallink'+j).val();
var isThere = cars.some(s => s === val )
例如:
let val = 'skype';
let cars = ["facebook", "amazon", "instagram", "twitter", "youtube", "paypal", "twitch", "tiktok", "cash.app", "onlyfans", "skype", "gofundme", "manyvids", "snapchat"];
let isThere = cars.some(s => s === val);
console.log(isThere);
更新:
如果要检查字符串是否包含另一个字符串,则可以使用方法:includes
let val = 'skype.com';
let cars = ["facebook", "amazon", "instagram", "twitter", "youtube", "paypal", "twitch", "tiktok", "cash.app", "onlyfans", "skype", "gofundme", "manyvids", "snapchat"];
let isThere = cars.some(s => val.includes(s));
console.log(isThere);
添加回答
举报