return not breaking foreach javascript