break not working in for loop javascript