问题描述
我有一个localStorage对象,其中包含是的,我已经解析过了。
I have a localStorage object that contains JSON data that yes, I have already parsed.
在该数据中,我希望在数组中搜索某些内容,例如此处所有内容 +关键字+此处所有内容;就像SQL Like’’查询一样。
Within that data, I wish to search an array for something, such as "ANYTHING HERE "+keyword+"ANYTHING HERE"; Like an SQL "LIKE ''" query.
啊,是的,indexOf似乎可以很好地工作。我现在要做的只是制作一个简单的RegExp来验证搜索输入(仅用于长度和字符-没什么。)
Ahh yes, indexOf seems to work fine for it. All I have to do now is just make a simple RegExp to validate the search input (only for length and characters--nothing fancy.)
您知道,我在工作希望可以在一个本地应用程序上将Google Chrome用户设置为他们的主页,并且希望我可以提出一些很酷的前所未有的功能。
You see, I am working on a local application that Google Chrome users will be able to set as their homepage, and hopefully, I can come up with some cool never-before-seen features.
推荐答案
如果您想知道一个字符串是否出现在另一个字符串中,则可能需要使用。
If you want to know if one string appears within another you might want to use the indexOf method.
if(jsonstring.indexOf(keyword) != -1){
console.log("keyword appears in jsonstring");
}
这篇关于JavaScript RegExp AKA中的LIKE'%$ word%'的相等性如何制作JavaScript搜索引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!