javascript check if array exists and is not empty