我來自 Python,并不完全熟悉“正確”的 JS/TS 做事方式。
我正在回圈遍歷一組元素,并將一些元素的串列推送到二維陣列中。
let res: number[][];
for (let posElement of posSet) {
if (negSet.has(-1*posElement)) {
res.push([-1*posElement, 0, posElement]);
}
}
我收到以下錯誤TypeError: Cannot read properties of undefined (reading 'push')
。我做錯了什么,我在哪里弄亂了語法?
uj5u.com熱心網友回復:
像這樣初始化
let res: number[][]=[];
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/494255.html
標籤:javascript 数组 打字稿 放