Getting the Username

<script type="text/javascript">
var user;
     AJS.$.ajax({
        url: "/rest/gadget/1.0/currentUser",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            user = data.username;
        }
     });
     alert(user);
</script>

 

Getting all Groups (as objects):

<script type="text/javascript">
var user;
     AJS.$.ajax({
        url: "/rest/gadget/1.0/currentUser",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            user = data.username;
        }
     });
var groups;
     AJS.$.ajax({
        url: "/rest/api/2/user?username="+user+"&expand=groups",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            groups = data.groups.items;
        }
     });
     alert(groups);
</script>

 

Sample for hiding menu items

This sample hides the "Create Subtask" for a user or a user with a particular group membership.

Reference: https://answers.atlassian.com/questions/212735/is-it-possible-to-show-create-sub-task-option-to-only-particular-group

<script type="text/javascript">
jQuery(document).ready(function($) {  
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) { 
hideTab();    
});
hideTab();  
function hideTab(){
        var user=getCurrentUserName();
//change group as per your requirement      
        if(isUserInGroup(user,'Developers')){           
            $("#create-subtask").hide();
            //if you want to hide "Convert to Sub-Task" operation then use this
            $("#issue-to-subtask").hide();
        }else{
            $("#create-subtask").show();
            $("#issue-to-subtask").show();
        }
 
}
function getCurrentUserName()
{
var user;
     AJS.$.ajax({
        url: "/rest/gadget/1.0/currentUser",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            user = data.username;
        }
     });
     return user;
}
   
   
function getGroups(user)
{
var groups;
     AJS.$.ajax({
        url: "/rest/api/2/user?username="+user+"&expand=groups",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            groups = data.groups.items;
        }
     });
     return groups;
}
function isUserInGroup(user, group){
    var groups = getGroups(user);
    for (i = 0; i < groups.length; i++){
         if (groups[i].name == group){
              return true;
         }
    }
    return false;
}   
});
</script>