I have an array that looks kind of like this memory[indexGroup][indexItem]. How can I check if that is valid, in other words if it would work when using console.log and getting a value back, not null, undefined or other non values. Empty, 0 and false are valid. These don't give errors.
This is what I ended up with (seems to work) but it's a mess:
function hasMemory() {
if( typeof memory === 'undefined') return;
if( typeof memory[indexGroup] === 'undefined') return;
if( memory[indexGroup] === null ) return;
if( typeof memory[indexGroup][indexItem] === 'undefined') return;
if( memory[indexGroup][indexItem] === null) return;
if( memory[indexGroup][indexItem] !== true ) return;
return true;
}
Scenarios
memoryis not setmemory[indexGroup]is not setmemory[indexGroup][indexItem]is not set
Then it should just return but if the full multidimensional array is valid, it should return true.
Is there a shorter/better/safer ways to check this?
function hasMemory(){ return Boolean(memory && memory[indexGroup] && memory[indexGroup][indexItem]) }