SharePoint Online Delete all Items from list using JavaScript Object model

Here we will discuss how to delete all SharePoint list items using JavaScript object model in SharePoint Online Office 365. I have used to code inside a script editor web part inside a web part page.

Below is the JavaScript object model.

Also read:
Steps to retrieve alternative languages from language settings in SharePoint online using JavaScript object model?

How to use Repeating Section in Nintex forms for Office 365 SharePoint online?

Get All Attachments From SharePoint 2013 List Item using Rest API

<input type=”button” id=”btnDeleteItems” value=”Click Here”/>

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

<script>

$(document).ready(function(){

$(“#btnDeleteItems”).click(function(){

DeleteAllItems();

});

});

function DeleteAllItems(){

var ctx = SP.ClientContext.get_current(),

list = ctx.get_web().get_lists().getByTitle(‘Ideas’),

query = new SP.CamlQuery(),

items = list.getItems(query);

ctx.load(items, “Include(Id)”);

ctx.executeQueryAsync(function () {

var enumerator = items.getEnumerator(),

itemArray = [];

while (enumerator.moveNext()) {

itemArray.push(enumerator.get_current());

}

for (var s in itemArray) {

itemArray[s].deleteObject();

}

ctx.executeQueryAsync();

});

}


</script>

Hope this will be helpful.


You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →