PnP-JS-Core library contains the number of extensible methods and properties using which we can achieve various actions in a simple code. To know more about this library component, visit the below links:
In this post, we will discuss how we can get all users from Site Collection using PnP-JS-Core library.
Example
The following code snippet is used to display each user's id and display name from the Site Collection using PnP JavaScript library, click here to read more.
- <script type="text/javascript" src="/siteassets/scripts/fetch.js"></script>
- <script type="text/javascript" src="/siteassets/scripts/promise.min.js"></script>
- <script type="text/javascript" src="/siteassets/scripts/pnp.min.js"></script>
-
- <div id="sample"></div>
-
- <script type="text/javascript">
-
- $pnp.sp.web.siteUsers.get().then(function(data) {
- var users = "";
- for (var i = 0; i < data.length; i++) {
- users += data[i].Id + " - " + data[i].Title + "<br/>";
- }
- document.getElementById("sample").innerHTML = users;
- });
- </script>