I have a 2-dimensional array that I want to check the bounds in Javascript. I prefer doing this without checking each index independently.
For example if my 2d array is...
dataset[row0-1][column+column0]
I really do not want to have to do the following...
if(row0-1 >0)
{
if(dataset[row0-1].length >= column+column0)
{
data = {label : dataset[row0-1][column+column0]};
}
}
The problem is that I have to first check the row and then check the column. I prefer doing both of these checks with one operation or on one line. Rather then returning an out of bounds error, why doesn't Javascript just return null or undefined?
For example, in a future version of Javascript, wouldn't it be better if we could do this?
if(dataset[row0-1][column+column0] != undefined)
{
data = {label : dataset[row0-1][column+column0]};
}
else
{
...
}