Retrieve all lists and libraries from SharePoint site using JavaScript object model (jsom)

This SharePoint jsom tutorial, we will discuss, how to retrieve all lists and libraries from SharePoint site using the JavaScript object model (jsom) in SharePoint Online Office 365.

The same jsom code we can use to retrieve all lists and libraries from SharePoint 2013/2016 sites.

Retrieve all SharePoint list and libraries using jsom

Here we have put the jsom code inside a script editor web part inside a web part page in the SharePoint site.

If you face one issue like Uncaught TypeError: SP.ClientContext is not a constructor error, then you can resolve by following this article.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<div id="divGetListData"></div>

<script>
$(function () {
ExecuteOrDelayUntilScriptLoaded(getAllLists, "sp.js");
});
var collList;
function getAllLists() {
var clientContext = new SP.ClientContext();
var oWebsite = clientContext.get_web();
collList = oWebsite.get_lists();
clientContext.load(collList);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed)
);
}

function onQuerySucceeded() {
var listInfo = ";
var listEnumerator = collList.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
listInfo += oList.get_title() + '<br />';
}
$("#divGetListData").html(listInfo);
}

function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}

</script>

Once you will save this code it will display all the lists and libraries from the SharePoint site like below:

Retrieve all SharePoint list and libraries using jsom

You may like following SharePoint jsom tutorials:

This SharePoint jsom tutorial, we learned how to get all the list and libraries from the SharePoint site using the JavaScript object model (jsom).

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

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

Bhawana Rathore

Hello Everyone!! I am Bhawana a SharePoint MVP and having about 8+ years of SharePoint experience as well as in .Net technologies . I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools . Now exploring more in SharePoint 2016 :) Hope here I can contribute and share my knowledge to the fullest. As I believe "There is no wealth like knowledge, and no poverty like ignorance"

>