if you are working on SharePoint 2013 Version, then it is easy to get current user groupcollection through rest api in javascript.
script would be like this :
function getCurrentUserGroupColl(UserID)
{
$.ajax
({
url: "/sites/dev/_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++)
{
console.log(results[i].Title)
}
}
});
}
function getCurrentUser()
{
$.ajax
({
url: "/sites/dev/_api/web/CurrentUser",
type: "GET",
headers: { "Accept": "application/json; odata=verbose","X-RequestDigest": $("#__REQUESTDIGEST").val() },
dataType: "json",
async: true,
success: function(data){
getCurrentUserGroupColl(data.d.Id)
}
});
}
$(document).ready(function(){ getCurrentUser(); });
Hope it helps!!