为什么我不能使用 array[i].x 访问数组中向量的元素?

Why can't I access the element of a vector in an array with array[i].x?

我收到此错误:无法读取未定义的属性(读取 'x')

let array = [];
let vector = new THREE.Vector3(2,3,2);
array.push(vector);
console.log(array[-1].x);

如果你想访问数组的最后一个元素,试试

array[array.length - 1]

或者更好,尝试 ES-2022 Array.prototype.at()

array.at(-1)