check for undefined  before calling $.each

calling `$.each` with `undefined` as argument throws an exception, I've added a guard to check for it