Passing part of an array to a function

admin

Administrator
Staff member
This is totally out of my league. I just envisioned a simple way to do this, but I have no idea if it is possible.

I have an array of holding a series of dates

marriedDate = new Array(1951,1,32,1958,13,32,1959,9,19,1982,1,22)

// refering to married, divorced, married, died
// The 32s are place keepers of uncertain dates

I have a function that converts this to a printed date

function datePrint(thisDate) {
document.writeln(thisDate[0]+' '+Month[thisDate[1]]+' '+thisDate[2]);
}

Previously, each date was a seperate 3 element array. Now I'm grouping them together so I can reuse a bunch of JS to deal with all the dates.

The question
Can I pass part of marriedDate to the datePrint function, or do I have to break it apart and pass the pieces and rewrite datePrint to deal with the pieces?

I can do it the latter way, but the code will get messy. It would be a lot cleaner code to do it the first way.
 
Back
Top