MV I want to do such a function but idk how, help!

First, I want to add three notetags to each weapon and armor
for example:
<level: 12><type: sword><rarity: 3>
<level: 4><type: hat><rarity: 0>
…………etc.etc...
There are 400 pieces of equipment in my database, they all have their note tags

now i want to create a function , three input(level,type,rarity), one return value(id)
Since I am a PHP coder, I don't know how to write javascript, so I have made something in my textbook:
QQ图片20211227184055.jpg


Can anyone help me? thx for any replies!
I am not a PHP programmer, so I am not quite sure what you are trying to accomplish here. Particularly I have no clue what condition ( == && == && ==) is. Maybe if you could describe what you want to accomplish through pseudo-code or just plain old English, I could try to help.
JavaScript:
var rollEquipment = function(level, rarity, type){
   const pool = [...$dataWeapons, ...$dataArmors].filter(db => db !== null && Number(db.meta.rarity) === rarity && Number(db.meta.level) === level && db.meta.type.trim() === type))
   return pool[Math.floor(Math.random() * pool.length)].id
}
Something like this?
JavaScript:
var rollEquipment = function(level, rarity, type){
   const pool = [...$dataWeapons, ...$dataArmors].filter(db => db !== null && Number(db.meta.rarity) === rarity && Number(db.meta.level) === level && db.meta.type.trim() === type))
   return pool[Math.floor(Math.random() * pool.length)].id
}
Something like this?
my god, i thought you were a composer , i was totally wrong!!!

thank you!

Original thread: https://forums.rpgmakerweb.com/threads/i-want-to-do-such-a-function-but-idk-how-help.143336/