If you are writing a regular userscript I recommend that you make use of the Wanikani Open Framework (WKOF)
With WKOF your script will be faster (no fetching through the API since WKOF caches items), easier to develop (WKOF is very handy), and have a lower load on WK.
Fetching all items that a user has not yet learned is as easy as this. Just fetch items with a filter for locked items (SRS level -1 in WKOF) and initiate items (SRS level 0)
wkof.include('ItemData');
wkof.ready('ItemData')
.then(fetch_items)
.then(do_stuff);
function fetch_items() {
return wkof.ItemData.get_items({
wk_items: {
options: {assignments: true,},
filters: {srs: [-1, 0],},
},
});
}
function do_stuff(items) {
// Do stff
}