SharePoint 2013/Online: Get current logged in user's groups using javascript

This Post explains how to get current logged in users Groups using javascript. Its a simple ajax call to the sharepoint service. Use the below code

$(document).ready(function () {
     var userid = _spPageContextInfo.userId;
function getCurrentUserGroups(UserID) {
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetUserById(" + UserID + ")/Groups",
        type: "GET",
        headers: { "Accept": "application/json; odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val() },
        dataType: "json",
        async: true,
        success: function (data) {
            /* get all group's title of current user. */
            var results = data.d.results;
            for (var i = 0; i < results.length; i++) {

Vikas Kottari

Hi. I’m a SharePoint Developer. I’m Microsoft Certified Professional on SharePoint. I work on O365, SharePoint 2016/2013/2010, SPFx and also I’m Full stack .NET Developer. I’m Foodie, Dreamer and Photographer. Inspired to make things looks better.