我有這門課如下。x 和 y 是二維坐標class Vector { constructor(x, y) { this.x = x; this.y = y; }}我有一個數組來存儲坐標 x 和 yconst coordinatesStorage = [];coordinatesStorage.push(new Vector(1, 2));coordinatesStorage.push(new Vector(3, 4));coordinatesStorage.push(new Vector(4, 6));我想查找坐標存儲數組中是否存在坐標(3,4)if ( coordinatesStorage.find(Vector{x:3, y:4}) ) { gameOver = true;} // this code does not work不幸的是,上面提到的是我的蹩腳方法,它無效并且返回控制臺錯誤。我有 C++ 背景。我正在嘗試將我的 Cpp 代碼轉換為 JS。請幫助該代碼以查找坐標存儲數組中是否存在坐標(3,4)
如何在包含坐標對的數組上使用 find 方法?
狐的傳說
2022-10-08 15:57:31