I have created JavaScript code using REST API for getting the username of a SharePoint user from an active directory if you know the ID. Please suggest any improvements.// get user name from idfunction getUserFromId(userid) {// var userid = _spPageContextInfo.userId;   var requestUri = _spPageContextInfo.webAbsoluteUrl + /_api/web/getuserbyid( + userid + );   var requestHeaders = {      accept: application/json;odata=verbose   };   $.ajax({      url: requestUri,      async: false,      contentType: application/json;odata=verbose,      headers: requestHeaders,      success: onSuccess,      error: onError  });   function onSuccess(data, request) {      var Logg = data.d;      userLoginName = Logg.Title;   }   function onError(error) {      alert(error);   }   return userLoginName;}
Get username from active directory if you know active directory Id in SharePoint
javascript;rest;sharepoint