如果在数组中找到值,则重定向浏览器 [英] Redirecting the browser if a value is found in an array
问题描述
我在js中创建了一个验证文件,如果他们点击的链接存储在文件中,我会将用户引导到另一个页面但是我需要包含if函数在文件中使用数组或某种类型的列表
thnx提前这里是我一直在使用的代码
Hi,
I have created a validation file in js that will direct users to another page if the link they clicked on is stored on the file however I need the if function contained in the file to work with arrays or a list of some sort
thnx in advance here is the code I have been working with
推荐答案
Hi Wangers,
我个人这样做的方式是延长Array js对象通过使用原型obje ct并添加一个contains方法,如果数组包含传入的字符串,则返回true:
Hi Wangers,
The way I would personally do this would be to extend the Array js object through use of the prototype object and add a contains method which returns true if the array contains the string passed in:
我想要不区分大小写
I want case insensitivity
引自PM
不区分大小写可以通过使用带有ai(不区分大小写)标志的正则表达式(regexp)。 regexp上可用的其他标志是g(全局),它匹配字符串的所有实例和m,这会导致使用多行。
无论如何,在这种情况下设置不区分大小写更改包含以下功能:
Quote from PM
Case insensitivity can be obtained by using a regular expression (regexp) with a i (case insensitive) flag. The other flags available on regexp is g (global) which matches all instances of a string and m which causes multiline to be used.
Anyway, to put case insensitivity in this case change the contains function to:
感谢您提供的所有帮助,脚本效果很好
thank you for all of your help the script works great
这篇关于如果在数组中找到值,则重定向浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!