#TypeError: Cannot read properties of undefined (reading 'map')

31 messages · Page 1 of 1 (latest)

tawny sail
#
{ name: "Ürün", value: sepetdata.map((urun) => urun.map((a, index) => `${index + 1}. ${a.name}`)).join("\n") },
                                                                  ^
TypeError: Cannot read properties of undefined (reading 'map')
#

I don't understand why it is giving this error here

stark pasture
tawny sail
#

I think I'm stupid. I still can't fix the error

#

It keeps giving this error about the button I brought.

#

When I remove the codes of that button, it fixes itself.

stark pasture
#

It's kinda normal that if you remove the code it fixes it. That is a basic part of javascript though, you should know how to handle possible undefined values. I also have no idea what you are trying to achieve, how it should work so I can't do much

#

You only copy pasted an error message and took a screenshot of it. I can't help just with this

tawny sail
#

Or should I tell you what I want to happen here?

stark pasture
# tawny sail I send you the code?

Like I explained. I am not in your head and I also cannot resd your mind. If you need help I need to know what you want it to do. What is not working (in this case I know the error) and what you currently did. So yes showing a code snippet of where the problem comes from is one of the points I need to understand what is happening

tawny sail
#
              { name: "Ürün", value: sepetdata.map((urun) => urun.map((a, index) => `${index + 1}. ${a.name}`)).join("\n"), inline: true },

this code will find the price of the product from the sepetdata and will provide the amount of discount the entered promo code can provide.

#

So I wanted it to be like this

#
var sepetdata = urun.sepet.map(a => a.urunler)

sepetdata defined

stark pasture
#

And what is the sepetdata looking like?

tawny sail
#

Are you asking as embed as code?

#

This is important code for me

#

If it didn't matter I would remove it

#

I'm going to eat

stark pasture
#

I am asking what the data is

#

what does sepetdata contains ?

tawny sail
#
_id
642315285544ce3d4139834d
memberId
"701518625760346172"
__v
0
tutar
50

urunler
Array

0
Object
_id
6422ef485dfba1af9209b81b
name
"Offline Discord 1000 Sunucu Üyesi (ANLIK)"
desc
"🟣 Sunucu davet linkiniz sınırsız süreli, sınırsız kullanıcılı olmalıd…"
ktgry
"Discord"
fiyat
50
foto
"https://cdn.discordapp.com/attachments/1085579577650327704/10902661340…"
urunKodu
872980
__v
0
stark pasture
#

well, that structure is not an array

#

you will not be able to use .map on it

#

you also didn't show much of the code, it almost seems like you are making an array with null values...

#

it's seems to be how you get sepetdata that is wrong

#

but now I would need to know what is urun

#

me guessing with is happening.

var sepetdata = urun.sepet.map(a => a.urunler)```
this code will make an array by mapping what sepet to become .urunler.
urunler doesn't exist on them so it does an array of undefined values
when you try to map them and call map on them again it errors out
#

here is an example

#

I map a.urunler but that's not a property, so it creates an array of undefined values. wich error out after when you try to use them