Dynamically get id of items

I have a for loop that pushes the ids of the items in the array into a new array, however Ruby is different from JavaScript and I can't seem to figure out how to accomplish this, here's how i did it in ruby:

Code:
for items_array.each do |i|
     new_array.push($data_items[i].id)
end

what is the equivalent in MV?
I know JavaScript but not Ruby, so I'm having trouble reading what the function you've placed here is actually doing. It seems to be creating new_array by calling from the database, but I'm not sure what items_array is or where i comes from. Can you clarify what you need the function to do?

EDIT: To clarify some of my confusion, in MV's JavaScript,
Code:
$dataItems[i].id
returns i. So to me (without knowing Ruby) it looks like you're taking an array of item ids and making that same array again, but by filtering it through the database for some reason. Also, there are TONS of array functions you can use to pull useful information from an array of actual item objects, so I really need to know what you're trying to accomplish and what you're starting with.
I believe the equivalent for what you have is a for...in loop, in JavaScript for...in loops are not recommended for arrays (they are useful for objects though).
Code:
//Here is a JavaScript version using a normal for loop
//Assuming itemArray and newArray are already defined variables
for (var i = 0; i < itemArray.length; i++) {
    newArray.push($dataItems[i].id);
}
@Llareian @Sarlecc Thank you both I'm pretty dumb for some reason I thought $dataItems.id wouldn't work when in fact it does.
Another post you might be interested in is this: for-each over an array in JavaScript. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/dynamically-get-id-of-items.86689/