check if the value is exists before trying to get length property