0

In my project i have arrays for date1, date2 and so on upto one month dates as shown below

var day1= [4,5,6,11];
var day2= [7,8,9,12];
var day3= [10,11,12,14];...
var day30= [1,2, 3, 4];

In the above each array exact size we dont know that may increase or decrease and i need to pass these values to the one more set of arrays like

var data1= [day1[0], day2[0], day3[0]];
var data2= [day1[1], day2[1], day3[1]];
var data3= [day1[2], day2[2], day3[2]];...
var data30= [day1[30], day2[30], day3[30]];

As per the day array size data array size will increase.

How to solve this issue any help..?

Jigar Joshi
241k42 gold badges409 silver badges446 bronze badges
asked May 15, 2012 at 10:33
3
  • 10 question 0 accepted answer............. Commented May 15, 2012 at 10:36
  • instead of day1..day30 you could use arrays. Array of arrays Commented May 15, 2012 at 10:36
  • your question is not very clear If you have problem with arraysize then try using arrayList Commented May 15, 2012 at 10:39

2 Answers 2

1

Consider using an object instead of variables:

var days = {
 day1: [4,5,6,11],
 day2: [7,8,9,12],
 ... 
 day30: [1,2, 3, 4]
};

Then you can do something like:

var data30 = [];
var i = 0;
while ( days.hasOwnProperty('day' + ++i) ){
 data30.push(days['day' + i]);
}

Though given the sample data, data30 won't have any members because the first array has no member at index 30.

Bergi
671k162 gold badges1k silver badges1.5k bronze badges
answered May 15, 2012 at 10:39
Sign up to request clarification or add additional context in comments.

Comments

0

Check out JavaScript's push method.

http://www.w3schools.com/jsref/jsref_push.asp
answered May 15, 2012 at 10:39

2 Comments

Please don't reference w3schools, reference the appropriate specification (W3C for DOM or ECMAScript for pure language items) and MSDN or MDN if examples seem useful.
ref: w3fools.com for why w3schools might not be the best reference to link to.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.