This should provide the requested results:
var lmsAPI = parent;
var name = lmsAPI.GetStudentName();
var id = lmsAPI.GetStudentID();
var nameArray = str.split(" ");
var firstName = nameArray[1];
var firstInitial = firstName.charAt(0);
var lastName = nameArray[0];
var cleanLastName = lastName.replace(/[^a-zA-Z]/g, "");
var userName = firstInitial + cleanLastName;
var userName = userName.toLowerCase();
var player = GetPlayer();
player.SetVar('first_name', firstName);
player.SetVar('last_name', lastName);
player.SetVar('first_initial', firstInitial);
player.SetVar('email', id);
player.SetVar('username', userName);