Jquery $.inarray() Not Working Properly With Array Made With Jquery Makearray()
I created an date array using this: var holidays = ['7/24/2010','7/25/2010']; var holidaysArray = jQuery.makeArray(holidays); and then testing to see if myDate (a date object)
Solution 1:
I think you are comparing Date
and String
objects, that's why you'll get always false.
see:
newDate("12/12/2000") == "12/12/2000"// this is false
EDIT:
Also! note that:
newDate("12/12/2000") == newDate("12/12/2000") // this is false too!
You should compare dates using their epoch time value like this
newDate("12/12/2000").valueOf() == newDate("12/12/2000").valueOf() // this is TRUE
Solution 2:
To summarize others' answers:
- You already have an array, you don't need to use makeArray().
- Your array doesn't contain dates, it contains strings.
- Dates can't be compared directly in JavaScript.
Solution 3:
Basically you want to perform a search (lookup), right?
If you formulate your array like this:
var holidays = [{ date: "7/24/2010" }, { date: "7/25/2010" }];
And create a jOrder table out of it, indexed by date (unique):
var table = jOrder(holidays)
.index('date', ['date']);
Then you can check the presence of a certain date in the table like this:
if (!table.where([{ date: myDate }]).length) {....}
Post a Comment for "Jquery $.inarray() Not Working Properly With Array Made With Jquery Makearray()"