作者:手机用户2502913853 | 来源:互联网 | 2024-10-17 15:29
This question already has an answer here:
这个问题已经有了答案:
- How do I check if an array includes an object in Javascript? 40 answers
- 如何检查数组是否包含Javascript中的对象?40的答案
I have a simple array with bank holidays:
我有一个简单的数组与银行假日:
var bank_holidays = ['06/04/2012','09/04/2012','07/05/2012','04/06/2012','05/06/2012','27/08/2012','25/12/2012','26/12/2012','01/01/2013','29/03/2013','01/04/2013','06/05/2013','27/05/2013'];
I want to do a simple check to see if certain dates exist as part of that array, I have tried:
我想做一个简单的检查,看看某些日期是否作为数组的一部分存在,我试过:
if('06/04/2012' in bank_holidays) { alert('LOL'); }
if(bank_holidays['06/04/2012'] !== undefined) { alert 'LOL'; }
And a few other solutions with no joy, I have also tried replacing all of the forwarded slashes with a simple 'x' in case that was causing issues.
我还尝试过用一个简单的“x”代替所有的斜线,以防出现问题。
Any recommendations would be much appreciated, thank you!
如有任何建议将不胜感激,谢谢!
(edit) Here's a jsFiddle - http://jsfiddle.net/ENFWe/
(编辑)这里有一个jsFiddle—http://jsfiddle.net/ENFWe/
3 个解决方案