0

I have this piece of code, when you look at it it would seem that the logic should run as follows:

I create 3 empty arrays, I add one value to bankSelectedData, I print out the values, obviously bankSelectedData is now 1 and bankSelectionArrayCurrent length is 0, but then I say:

bankSelectionArrayPrevious = bankSelectionArrayCurrent; 

So I'm turning bankSelectionArrayPrevious into bankSelectionArrayCurrent. When I check the size of bankSelectionArrayPrevious is says '1' ?? How is this possible?

var bankSelectionArrayCurrent = new Array(); var bankSelectionArrayPrevious = new Array(); var bankSelectedData = new Array(); bankSelectedData.push("value1"); alert("bankSelectionArrayCurrent length: "+bankSelectionArrayCurrent.length); alert("bankSelectedData length: "+bankSelectedData.length); if(bankSelectedData.length != bankSelectionArrayCurrent.length){ bankSelectionArrayPrevious = bankSelectionArrayCurrent; bankSelectionArrayCurrent.length = 0 alert("previousSize: "+bankSelectedData.length); alert("currentSize: "+bankSelectionArrayCurrent.length); }​ 

Thanks for any advice!

1
  • Ahh I'm such an idiot!.. Thanks guys.. Commented Mar 19, 2012 at 13:06

3 Answers 3

2

Where you have

alert("previousSize: "+bankSelectedData.length); 

perhaps you meant:

alert("previousSize: "+bankSelectionArrayPrevious.length); 
Sign up to request clarification or add additional context in comments.

Comments

2

Your code never changes "bankSelectedData", so its length remains 1 after you add that first value.

Your code does not contain any alert() call with the length of "bankSelectionArrayPrevious".

Comments

2

Your alert is wrong. It should be:

alert("previousSize: "+bankSelectionArrayPrevious.length); 

Comments