JavaScript two-dimensional array Cannot read property 'push' of undefined

use JS to LeetCode, to question 6 ZigZag Conversion report an error TypeError: Cannot read property "push" of undefined

/**
 * @param {string} s
 * @param {number} numRows
 * @return {string}
 */
var convert = function(s, numRows) {
    var rowArray = new Array(numRows),
        dir = true,
        n = 1,
        i = 0,
        temp = 0,
        rowArrayCount = 0,
        ans = "",
        len = s.length;
    
    for (i = 0; i < numRows; iPP) {
        rowArray[i] = new Array();
    }
    
    while (i<len) {
        console.log(rowArray);
        console.log(rowArray instanceof Array);
        console.log(rowArray[rowArrayCount] instanceof Array);
        while(dir) {
            rowArray[rowArrayCount].push(s.charAt(i));
            rowArrayCountPP;
            iPP;
            if (i === numRows*n -1) {
                dir = false;
                nPP;
                rowArrayCount = numRows-1;
            }
        }
        while(!dir) {
            rowArray[rowArrayCount].push(s.charAt(i));
            rowArrayCount--;
            iPP;
            if (i === numRows*n -1) {
                dir = true;
                nPP;
                rowArrayCount = 0;
            }
        }
    }
    
    for (i = 0; i < numRows; iPP) {
        temp = rowArray[i].join("");
        ans += temp;
    }
    return ans;
};

where

console.log(rowArray);
console.log(rowArray instanceof Array);
console.log(rowArray[rowArrayCount] instanceof Array);

output is:

clipboard.png

Why is rowArray [rowArrayCount] an array but not the push method?

Feb.16,2022

rowArrayCount = numRows-1
where rowArrayCount may cause the array to cross the bounds



rowArrayrowArray[rowArrayCount]undefinediforiforifori0<br>:

/**
 * @param {string} s
 * @param {number} numRows
 * @return {string}
 */
 var convert = function(s, numRows) {
    if(numRows === 1) {
        return s;
    }
    var rowArray = new Array(numRows),
        dir = true,
        n = 1;
        i = 0,
        temp = 0,
        rowArrayCount = 0,
        ans = "",
        len = s.length;
    
    for (i = 0; i < numRows; iPP) {
        rowArray[i] = new Array();
    }
    i = 0; //i0
    while (i<len) {
        while(dir) {
            rowArray[rowArrayCount].push(s.charAt(i));
            rowArrayCountPP;
            iPP;
            if (i === (numRows-1)*n) {
                dir = false;
                nPP;
                rowArrayCount = numRows-1;
            }
        }
        while(!dir) {
            rowArray[rowArrayCount].push(s.charAt(i));
            rowArrayCount--;
            iPP;
            if (i === (numRows-1)*n) {
                dir = true;
                nPP;
                rowArrayCount = 0;
            }
        }
    }
    
    for (i = 0; i < numRows; iPP) {
        temp = rowArray[i].join("");
        ans += temp;
    }
    return ans;
};
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b543-2bad0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b543-2bad0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?