I need to loop through an entire 2D array (OldTable) to check that Column1 has a value of 1 and Col7 is not empty (null). If the above conditions are true then push the current (i) arrays of elements into newTable. My snippet of JS is as follow...
var newTable = [];
for (var i=1; i<OldTable.length; i++){
if(OldTable[i][0]==1 && OldTable[i][7]!==null){
newTable.push(OldTable[i]);
}
}
Seems like a fairly straight forward thing to do but currently hitting brick wall with this error...
TypeError: Cannot read property "0" from undefined. (line 80, file "Code"
I have tried to reduce the if statement to just...
if(OldTable[i][0]==1){
...but still the same error. I'm able to display the array element just fine using...
Browser.msgBox(OldTable[50][0]);
I'm fairly new to JS so could be a simple silly error someone could point out.
UPDATE: In trying to simplying naming, I've actually made it more difficult with conflicting terminology, so have going through and updated the variable names used.
newArrayinstead ofArrayinside of your loop?Array? Check if its of proper typeArray??? like, the built-in Array object that comes with every javascript engine since the 90's?OldTableis defined and has length property as code is entering loop. Issue is in value ofOldTable[i]. Its not an array