I have a problem in my code, I accumulate a dataset into an object "pOptions" Then I add the contents of this object into an array of another object "dDept[vDept]". Next I want to reset the value of the first object "pOptions", so new values can be accumulated and transferred into the 2nd object "dDept[vDept]". But when I reset the value of the first object "pOptions" to blank then the 2nd array object "dDept[vDept]" is also wiped out. How can I prevent this. Here is my code:
Code:
var dDept = new Object();
var vDept = aPhaseCodes[0].substring(0,4);
var pOptions = new Array();
for (var i = 0; i < aPhaseCodes.length; i++ )
{
var pCode = aPhaseCodes[i].substring(5,7);
if (vDept == aPhaseCodes[i].substring(0,4))
{
pOptions[pOptions.length] = {value:pCode,text:pCode};
}else{
dDept[vDept] = pOptions;
//problem occurs here
pOptions.length = 0;
vDept = aPhaseCodes[i].substring(0,4);
pOptions[pOptions.length] = {value:pCode,text:pCode};
}
}
dDept[vDept] = pOptions;
Comment