我想要一个更小的方式来写这个条件我试图简化它但它不适合我
if(( data.includes(userId) || data.includes(userId.toString()) || data.includes(username) )) console.log(true)
这个条件很好,但我想要一个简化版本
最佳答案
您可以使用 the some
Array method测试多个谓词。要么
if ([userId, userId.toString(), username].some(x => data.includes(x))) …
或
if (data.some(x => [userId, userId.toString(), username].includes(x))) …
关于javascript - 有没有更优雅的方式来写这个条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45805931/