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?
CodePudding user response:
like this initialize
let res: number[][]=[];