javascript foreach return early