javascript check if array is defined and not empty