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.
JavaScript
x
7
1
let res: number[][];
2
for (let posElement of posSet) {
3
if (negSet.has(-1*posElement)) {
4
res.push([-1*posElement, 0, posElement]);
5
}
6
}
7
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?
Advertisement
Answer
like this initialize
JavaScript
1
2
1
let res: number[][]=[];
2