Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pushing array into an array of array in TS

I am coming from Python, and am not entirely familiar with the ‘proper’ JS/TS way of doing things.

I am looping through the elements of a set, and I am pushing lists of some of the elements onto a 2D array.

let res: number[][];
for (let posElement of posSet) {
    if (negSet.has(-1*posElement)) {
        res.push([-1*posElement, 0, posElement]);
    }
}

I am getting the following error TypeError: Cannot read properties of undefined (reading 'push'). What am I doing wrong, where am I messing up the syntax?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

like this initialize

let res: number[][]=[];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading