PnP-JS-Core library contains a number of extensible methods and properties. By using this, we can achieve various actions in a simple code. To know more about this library component, visit the links given below:

In this post, we will see how to get all the groups from the Site Collection, using PnP-JS-Core library,

Example

The code snippet, given below, is used to get the group name and the group owner name from the Site Collection , using PnP JavaScript library. Click here to read more.

  1. <script type="text/javascript" src="/siteassets/scripts/fetch.js"></script>
  2. <script type="text/javascript" src="/siteassets/scripts/promise.min.js"></script>
  3. <script type="text/javascript" src="/siteassets/scripts/pnp.min.js"></script>
  4. <div id="sample"></div>
  5. <script type="text/javascript">
  6. //The below PnP property used to returns all groups from site collection
  7. $pnp.sp.web.siteGroups.get().then(function(data) {
  8. var groups = "";
  9. for (var i = 0; i < data.length; i++) {
  10. groups += data[i].Title + " - " + data[i].OwnerTitle + "<br/>";
  11. }
  12. document.getElementById("sample").innerHTML = groups;
  13. });
  14. </script>