# How to delete all items from a Collection using wix code

**URL:** <https://forum.wixstudio.com/t/how-to-delete-all-items-from-a-collection-using-wix-code/25846>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [January 11, 2018, 9:01pm UTC](https://forum.wixstudio.com/t/how-to-delete-all-items-from-a-collection-using-wix-code/25846 "2018-01-11T21:01:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![harrum-noor](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/harrum-noor/32/1537_2.png) [@harrum-noor](https://forum.wixstudio.com/u/harrum-noor)\
**Post date:** [January 11, 2018, 9:01pm UTC](https://forum.wixstudio.com/t/how-to-delete-all-items-from-a-collection-using-wix-code/25846/1 "2018-01-11T21:01:17Z")

</div>

I have a collection and i want to delete all items from it when the user navigates to a page, i have used the code below in the onReady function of that page but it isn’t working, can someone help me out please.  
(dataset1 is the dataset of the collection i want to remove all items from)

$w.onReady(function () {  
$w(“#dataset1”).onReady(async() =\> {  
if ($w(“#dataset1”).getCurrentItem()) {  
await $w(“#dataset1”).remove();  
while ($w(“#dataset1”).hasNext()) {  
await $w(“#dataset1”).next();  
await $w(“#dataset1”).remove();  
}  
}  
});  
});
