Created
February 22, 2017 04:47
-
-
Save sarfarazansari/a1288d41a050af25ee0b43fb629932b1 to your computer and use it in GitHub Desktop.
check if 2 dimensional array is empty and undefined by using try catch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr1 = [ | |
['A', 'B', 'C'], | |
['D', 'E', 'F'] | |
]; | |
var arr2 = [ | |
['A', 'B', 'C'], | |
[] | |
]; | |
var arr3 = [ | |
['A', 'B', 'C'] | |
]; | |
function is2dArrayEmptyOrUndefined(_arr, _index1, _index2) { | |
try { | |
if (_arr[_index1] !== undefined && _arr[_index2] !== undefined && _arr[_index2].length > 0 && _arr[_index1].length > 0){ | |
return false; | |
} | |
else{ | |
return true; | |
} | |
} | |
catch(e) { | |
return true; | |
} | |
} | |
// should return FALSE | |
console.log(is2dArrayEmptyOrUndefined(arr1, 0, 1)); | |
// should return TRUE | |
console.log(is2dArrayEmptyOrUndefined(arr2, 0, 1)); | |
// should return TRUE | |
console.log(is2dArrayEmptyOrUndefined(arr3, 0, 1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment