Can be acheaved by REST API too,
get the all groups that user belongs to:
"/_api/web/GetUserById(" + userId + ")/Groups"
in function:
GetUserGroups = function(userId){
var Id = _spPageContextInfo.userId
if (typeof userId != 'undefined' && userId!=""){
Id = userId;
}
var result = [];
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetUserById(" + Id + ")/Groups",
method: "GET",
async:false,
headers: {
"Accept": "application/json; odata=verbose",
"Content-Type": "application/json;odata=verbose",
},
success: function(data){
result = data.d.results
}
})
return result;
}