Check if a user belongs to a SharePoint group using JavaScript

This SharePoint jsom tutorial explains, how we to check if a user belongs to a SharePoint group or not using the JavaScript client object model (jsom).

The jsom code we can use to check if user belongs to SharePoint group in SharePoint Online, SharePoint 2016/2013 also.

Check if user belongs to a SharePoint group JavaScript

Below is the full code to check user belongs to SharePoint group using jsom:

function isUserMemberOfSharePointGroup() {
var currentContext = new SP.ClientContext.get_current();
var currentWeb = currentContext.get_web();
var currentUser = currentContext.get_web().get_currentUser();
var allGroups = currentWeb.get_siteGroups();
var group = allGroups.getByName('MyTestGroup');
var groupUsers = group.get_users();
function OnSuccess(sender, args) {
var userInGroup = false;
var groupUserEnumerator = groupUsers.getEnumerator();
while (groupUserEnumerator.moveNext()) {
var groupUser = groupUserEnumerator.get_current();
if (groupUser.get_id() == currentUser.get_id()) {
userInGroup = true;
alert (userInGroup);
function OnFailure(sender, args) {
alert('Something wrong happened !!!');

Check if user belongs to a SharePoint group JavaScript

Here is another example, how we to check if the current logged in user belongs to a particular SharePoint group using JavaScript object model.

Here I have a SharePoint group as “Team Site Owners” where I am checking if the current user belongs to the particular group or not.

I have put the below JavaScript code inside a script editor web part in the SharePoint web part page.

<input id="btnCheckUserCurrentGroup" onclick="CheckCurrentUserBelongstoGroup()" type="button" value="Check current user belongs to group" />

<script src="" type="text/javascript"></script>

<script type="text/javascript">
var userGroups;
function CheckCurrentUserBelongstoGroup()
var clientContext = new SP.ClientContext.get_current();
this.currentUser = clientContext.get_web().get_currentUser();
userGroups = this.currentUser.get_groups();


function OnQuerySucceeded() {
var isMember = false;
var groupsEnumerator = userGroups.getEnumerator();
while (groupsEnumerator.moveNext()) {
var group= groupsEnumerator.get_current();
if(group.get_title() == "Team Site Owners") {
isMember = true;

function OnQueryFailed() {
alert('Error occured');


You may like following SharePoint jsom tutorials:

This SharePoint tutorial explains, how to check if the user belongs to a sharepoint group javascript object model (jsom) in SharePoint Online/2013/2016.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.