function getsiteGroups() {
var clientContext = SP.ClientContext.get_current();
oGroups = clientContext.get_web().get_siteGroups();
clientContext.load(oGroups);
clientContext.executeQueryAsync(
Function.createDelegate(this, function(){
var groupsInfo = '';
var groupsEnumerator = oGroups.getEnumerator();
while (groupsEnumerator.moveNext()) {
var oGroup= groupsEnumerator.get_current();
groupsInfo += '\n' + 'Group ID: '+oGroup.get_id() + ', ' +'Title : '+ oGroup.get_title(); }
console.log(groupsInfo.toString());
}),
Function.createDelegate(this, function(){console.log('failed');}));
}
function injectMethod(){
getsiteGroups();
}
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");Code snippet works in Office 365 and SharePoint 2013 +This code snippet helps to retrieve the group ID and Title from the current Site Collection
