check if array is not undefined javascript