【发布时间】:2023-04-03 10:06:01
【问题描述】:
lodash 中有没有办法检查一个字符串是否包含数组中的一个值?
例如:
var text = 'this is some sample text';
var values = ['sample', 'anything'];
_.contains(text, values); // should be true
var values = ['nope', 'no'];
_.contains(text, values); // should be false
【问题讨论】:
-
不用lodash
values.some(el => text.indexOf(el) > -1)btw 也可以轻松完成。
标签: javascript lodash