jquery - Create an Array of names of last 7 days starting from today - javascript -


i'm trying figure out, how create javascript array of names of ie. last 7 days starting today.

i know getday() return number of day, can use index access element of array containing days of week.
give me name of today, need go chronologically create array of last few days couldn't find similar problem on web.

any elegant solution this? jquery perhaps?

see jsfiddle:

edit: store 7 days variable

http://jsfiddle.net/vdesign/y7ggqzrf/1/

var days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saterday', 'sunday']; var gobackdays = 7;  $(function() {     var today = new date();     var dayssorted = [];      for(var = 0; < gobackdays; i++)     {         var newdate = new date(today.setdate(today.getdate() - 1));         dayssorted.push(days[newdate.getday()]);     }      alert(dayssorted);  });  //output:  //[thursday, wednesday, tuesday, monday, sunday, saterday, friday] 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -