将数组推入TS中的数组
我来自Python,并且并不完全熟悉“适当”的JS/TS做事方式。
我正在浏览一组元素,然后将其中一些元素的列表推向2D数组。
let res: number[][];
for (let posElement of posSet) {
if (negSet.has(-1*posElement)) {
res.push([-1*posElement, 0, posElement]);
}
}
我收到以下错误typeError:无法读取未定义的属性(读取'push')
。我在做什么错,我在哪里弄乱语法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的初始化
like this initialize