What is the most portable way to delete element from multidimensional sparse array in javascript?
Will following work well if rows can be undefined sometimes?
if( content[row] ) {
delete content[row][col];
}
Will this work and will it be better?
if( r=content[row] ) {
delete r[col];
}
It depends.
deletewill leave an empty space in the array where the element was, like this:To remove an element from an array without leaving a hole, you should use
splice():Both of your examples work just fine — if
content[row]doesn’t exist, the body of theifstatement won’t be evaluated.