Is there a way to reference an item by the item index number in an event?

I am trying to do an event where I store a number in a variable and then use that to retrieve the type of item. I am then using that to give that particular item to the party. Is there a way to do this?
Here you go!

Code:
const itemId = $gameVariables.value(YOUR_VARIABLE_ID);
$gameParty.gainItem($dataItems[itemId], 1)

Replace YOUR_VARIABLE_ID with your variable Id. Additionally, you can replace 1 with any other number to give more items to the Party.
Awesome thank you!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-way-to-reference-an-item-by-the-item-index-number-in-an-event.135467/