Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript and tipped arrays [duplicate]

I am developing a web page with JavaScript and HTML. I am use jQuery and I must highlight a selected dates. I have that array:

var events = [ 
{ Title: "Five K for charity", Date: new Date("02/13/2013"), dir: "http://www.google.es" }, 
{ Title: "Dinner", Date: new Date("02/25/2013") }, 
{ Title: "Meeting with manager", Date: new Date("03/01/2013") }
];

My question is, how I can add an element in that array? I tried a lot of things and I dont know how. And another question, what is the name of that kind of array?

EDIT:

I see one thing. If a add a date like "01/05/2013", the array is like that:

Wed Feb 13 2013 00:00:00 GMT+0100 (Hora de verano romance)
Mon Feb 25 2013 00:00:00 GMT+0100 (Hora de verano romance)    
Fri Mar 01 2013 00:00:00 GMT+0100 (Hora de verano romance)
Sat Jan 05 2013 00:00:00 GMT+0100 (Hora de verano romance) 

And prints the date in the datepicker. But if I add a date like "05/05/2013" then:

Wed Feb 13 2013 00:00:00 GMT+0100 (Hora de verano romance)
Mon Feb 25 2013 00:00:00 GMT+0100 (Hora de verano romance)
Fri Mar 01 2013 00:00:00 GMT+0100 (Hora de verano romance)
Sun May 05 2013 00:00:00 GMT+0200 

You will see? The new date its diffent of the other. And in this case, the date are not highlited in the datepicker. Anyone knows why?

like image 513
Elseine Avatar asked May 29 '13 19:05

Elseine


1 Answers

There is no a true name for that array, it's just an Array of Objects. To append a new Object you have to do this:

events.push({Title: '...', ...}); //define the object to be appended

To define a new Date object you should use this constructor:

var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
//in this case it will be(month goes from 0 to 11)
new Date(2013, 4, 5); //this will be the 5th of May(which is 4)

There are a lot of methods for the Date Object, you just have to choose which one is the best for your purposes!

Reference to the Date Object - MDN

like image 55
Niccolò Campolungo Avatar answered Oct 04 '22 19:10

Niccolò Campolungo