#.filter is undefined

1 messages · Page 1 of 1 (latest)

gusty quartz
#

I tried to remove the nickname from the usege, but he rolls it once and writes that .filter is undefined

 if(SubCMD == "deleteuse") {
    if(args.length != 3) return player.sendMessage(ArgumentErrorMessage);
    if(!player.hasTag("admin")) return  player.sendMessage(AdminErrorMessage);
    const updatepromo = DB.get("promo")
    const proverka = updatepromo.filter(element => element.name == args[1])
    const playerProv = proverka[0]?.usage?.find(element => element == args[2]) ?? 0
    if(proverka.length == 0) {
       return  player.sendMessage("§r§c> Такой промокод не существует!") 
    } else if (playerProv.length == 0) {
      console.warn(JSON.stringify(proverka[0].usage))
      return player.sendMessage("§r§c> Игрок не использовал промокод") 
      };
    const NewPromoUpdate = updatepromo.filter(element => element.name != args[1]);
    const UsegeData = proverka[0].usege.filter(element => element != args[2])
   console.warn(JSON.stringify(proverka), JSON.stringify(UsegeData))
    NewPromoUpdate.push({
      name: proverka[0].name,
      usage: Array.from(UsegeData),
      max: proverka[0].max
    })
    console.warn(JSON.stringify(proverka[0].usege))
    DB.set("promo", NewPromoUpdate)
    player.sendMessage("§2Команда выполнена успешно")
            console.warn(JSON.stringify(DB.get("promo")))
    }
narrow voidBOT
#
Debug Result

There are 19 errors in this [code](#1129499043857449061 message).
Please read the attached file for the result.

little adder
gusty quartz
#

hm

#

but when I checked proverka[0].usege, it told me that it was an array

#

and for some reason it works for the first time

little adder
#

then the first one is an array but second isn’t

#

actually it should be an array

#

hm

#

Well I haven’t read the code but it’s because: 1 it’s undefined. 2 it’s not the correct type

#

so check for that

#

best way to check is to console warn the .get()

gusty quartz
#

hm now proverka[0].usege gives undefined

#

but why..

#

console.warn(proverka) = [{
"name":"farmfarrm",
"usege":["traileks"],
"max": "inf"
}]

#

stop

#

right now it gave out correctly

#

okay

gusty quartz
#

but when calling usege, he says that there is an error

#

what.. again it outputs an array

#

Okay I'll try it myself

#

WHAT