最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】js中判断字符串是否在一个列表中

字符串 crifan 1141浏览 0评论
折腾:
【未解决】给绘本查询web版增加点击tag标签搜索
期间,对于已有一个str的list:
curQueryDictKeys=(3) ["q", "tag", "difficulty"]
现在需要去判断字符串”tag”是否在list中
去用:
结果不行。
去搜:
js str in list
Determine if string is in list in JavaScript – Stack Overflow
Array.indexOf:
['a', 'b', 'c'].indexOf(str) >= 0
ES6:
['a', 'b', 'c'].includes('b')
Javascript list contains a string – Stack Overflow
$.inArray()
Javascript: Check If String In List | Lua Software Code
underscore or lodash:
_.indexOf['apple', 'orange', 'banana'], value)
【总结】
此处去用:
var isTagSearch = curQueryDictKeys.includes("tag") && curQueryDictKeys.includes("difficulty")
即可实现判断字符串数组中是否包含某个字符串。

转载请注明:在路上 » 【已解决】js中判断字符串是否在一个列表中

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
80 queries in 0.170 seconds, using 22.11MB memory