我有一个名为positions
的8x8二维数组,我想知道如何检查索引是否已定义。我看到了一个使用的示例。
if (typeof positions[8] === "undefined") alert('undefined');
但是当我尝试使用行和列的索引时,代码如下:
if (typeof positions[8][0] === "undefined") alert('undefined');
我在遇到错误:
Uncaught TypeError: Cannot read property '0' of undefined
有没有一种方法可以检查一个二维数组的索引是否存在,不仅对于一个索引而言,而是对于两个维度的索引都要检查?