afish674 Posted May 21, 2012 Share Posted May 21, 2012 I have an array that shows culminatively the number of days in a year. Jan the first starts with 0 and then Feb 1st starts with 31 etc. var months = new Array(); months[0]=0; months[1]=31; months[2]=59; months[3]=90; months[4]=120; months[5]=151; months[6]=181; months[7]=212; months[8]=243; months[9]=273; months[10]=304; months[11]=334; I want to change this for a leap year so that everything after Feb (array element 2 onwards) has +1 added to their values. I could do this via the splice method: months.splice(2,1,60);months.splice(3,1,91)//etc.. But this seems long winded, is there a quicker way? Like putting "months.splice(2,10,value+1);" or something similar? Thanks! Link to comment Share on other sites More sharing options...
Ingolme Posted May 21, 2012 Share Posted May 21, 2012 Loop through all the months and add 1 to their values: if(isLeapYear) { for(i = 2; i < months.length; i++) { months[i]++; }} Link to comment Share on other sites More sharing options...
afish674 Posted May 22, 2012 Author Share Posted May 22, 2012 Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now