logo       

[jQuery] Re: inArray not working with dates: msg#02914

jQuery

Subject: [jQuery] Re: inArray not working with dates


This is nothing specific to dates.

Every time you use the 'new' operator, you get a new object.

When you use == or === to compare two objects, it doesn't mean "tell me if
these two objects represent the same underlying value". It means "tell me if
these are two references to *the same object*".

For example:

function Foo() {}
var f1 = new Foo;
var f2 = new Foo;
var f3 = f1;

alert( f1 == f2 ); // false - two different objects
alert( f1 == f3 ); // true - both are references to the same object

-Mike

> From: Fontzter
>
> Well, I guess this is intrinsic to javascript. I didn't know
> that date compares were not reliable. Seems to work with
> milliseconds though. Learn something new every day.
>
> var dt1 = new Date(2009,7-1,31);
> var dt2 = new Date(2009,7-1,31);
> alert(dt1 === dt2); //false
> alert(dt1 == dt2); //false
> alert(dt1.getTime() === dt2.getTime()); //true
>
> Dave
>
>
> On Jul 31, 10:16 am, Fontzter <dmfo...@xxxxxxxxx> wrote:
> > Can someone tell me what I may be doing wrong here?
> >
> >         var dateList = new Array();
> >         dateList.push(new Date(2009,7-1,29));
> >         dateList.push(new Date(2009,7-1,30));
> >         dateList.push(new Date(2009,7-1,31));
> >         var testdate = new Date(2009,7-1,30);
> >         alert($.inArray(testdate,dateList)); //returns -1  ????
> >
> > tia,
> >
> > Dave
>

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | Mail Home | sitemap | FAQ | advertise