javascript - 使用 lodash 在带有整数的数组中查找字符串元素包括不工作
问题描述
这是我的代码,我正在使用 vuejs:
pins: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], //my data
isThisPin(pin){
return _.includes(this.pins, pin);
}
console.log(this.isThisPin('X')); //it returns true
基本上我试图猜测所选引脚是否不包含在引脚中,我希望将其返回为假,但它只是继续返回为真。
我使用了错误的功能吗?
解决方案
如果你想使用 lodash,你可以使用 _.contains 片段也可以和 lodash 一起使用
_.contains([1, 2, 3], 'X') // false
var pins = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
//alert(_.includes(pins, 'X'));
function checkPin(pin){
return _.includes(pins,pin )
}
alert(checkPin('X'));
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>
推荐阅读
- python - 使用 Sklearn 的多类多标签混淆矩阵
- python - 如何使用scrapy抓取需要登录的网站?
- firebase - Flutter - Dart:等待 forEach 结束
- oop - 面向对象的设计。有什么更好的?
- python - 匹配多个以结尾的字符串
- java - getResource 方法中的空指针异常
- c++ - CMake VisualStudio 找不到库
- plesk - 如果 Plesk 中缺少邮件选项卡的域,如何通过 Windows 服务器的命令行启用它
- c - 可以通过 localhost 连接到我的程序,但无法使用网络上的其他计算机连接
- c# - Entity Framework Core 和 MS Access