The problem in your code is, you are referencing removeByLoginName but you are passing email ID to delete the user. so try the below code,
Deleting user by Email ID:
'use strict';
var hostweburl;
var appweburl;
// Get the URLs for the app web the host web URL from the query string.
$(document).ready(function()
{
//Get the URI decoded URLs.
hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
// Resources are in URLs in the form:
// web_url/_layouts/15/resource
// Load the js file and continue to load the page with information about the folders.
// SP.RequestExecutor.js to make cross-domain requests
$.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js", getuser);
});
function getuser()
{
var executor;
var userEmail = "[email protected]";
// Initialize the RequestExecutor with the app web URL.
executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: appweburl + "/_api/SP.AppContextSite(@target)/web/sitegroups(6)/users/getbyemail('" + userEmail + "')?@target='" + hostweburl + "'",
method: "POST",
headers: {
"X-HTTP-Method": "DELETE"
},
success: function(data) {
alert("User Deleted successfully in SharePoint Group");
},
error: function(err) {
alert("error: " + JSON.stringify(err));
}
});
}
//Utilities
// Retrieve a query string value.
// For production purposes you may want to use a library to handle the query string.
function getQueryStringParameter(paramToRetrieve) {
var params = document.URL.split("?")[1].split("&");
for (var i = 0; i < params.length; i = i + 1) {
var singleParam = params[i].split("=");
if (singleParam[0] == paramToRetrieve) return singleParam[1];
}
}
Deleting user by Login Name:
<script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
var removeUserUrl = "/_api/web/sitegroups/getbyname('Employee')/users/removeByLoginName";
var metadata = {
'loginName': 'i:0#.w|SharePointHOL\\KarthikJagan'
};
removeUser(removeUserUrl, metadata)
});
function removeUser(removeUserUrl, metadata) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + removeUserUrl,
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose"
},
data: JSON.stringify(metadata),
success: function(data) {
console.log(data);
console.log("User has been successfully removed from the SharePoint Group.");
},
error: function(error) {
alert(JSON.stringify(error));
}
});
}
</script>
For more information, kindly have a look at the below links,
https://www.c-sharpcorner.com/article/add-and-remove-users-from-security-group-in-sharepoint-2016-using-rest-api/
https://social.msdn.microsoft.com/Forums/office/en-US/1c70bfb1-039d-43cd-94b5-6138893bde8b/rest-api-removedelete-sp-user-from-group?forum=sharepointdevelopment
https://www.c-sharpcorner.com/UploadFile/91b369/how-to-delete-users-from-the-group-in-sharepoint-using-rest/