MV Remove all items from inventory except Key Items or Quest Items

Hi all, I'm wondering if someone could help me out with what I assume is a simple issue. I want to clear the party's inventory except Key Items. I have figured out how to remove all items with a script call but I would like to exclude Key Items or if possible since I'm using Yanfly's Item Categories one of my custom categories. Any help would be much appreciated.
$gameParty.items().forEach(function(item) { if (item.itypeId !== 2) $gameParty.loseItem(item, 99) });
Awesome! Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/remove-all-items-from-inventory-except-key-items-or-quest-items.126340/