How to clear inventory by script?

How can I quickly empty the party inventory?

I am working on a puzzle game where the player needs to reset his items (such as keys left over from a previous level) when he enters a new level, and removing them one by one using "Change Items" is terribly inefficient.

Thanks!
This as a script call will completely delete all items the party has.

Code:
$gameParty._items = {};

If you want to restore the items later, you have to save it to a variable first.

Code:
$gameVariables.setValue(7, $gameParty._items);
$gameParty._items = {};

// to restore the items
$gameParty._items = $gameVariables.value(7);
@Aloe Guvner Thanks so much! This is very useful.

Is there a way to get rid of a specific block of items too? For example I want to remove just items 10-23 (the keys for example), but have the party keep some of the other stuff between levels.
Is there a way to get rid of a specific block of items too? For example I want to remove just items 10-23 (the keys for example), but have the party keep some of the other stuff between levels.

Code:
for (var i = 10; i <= 23; i++) {
  delete $gameParty._items[i];
}
or
Code:
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23].forEach(function(itemId) {
  delete $gameParty._items[itemId];
});

Original thread: https://forums.rpgmakerweb.com/threads/how-to-clear-inventory-by-script.104675/