Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ignium's avatar

The same concept should apply in the case of divs. You just need to update the createDiv() function to call a property. You're already passing the array to the createElements() function, which in turn loops through each individual product and passes it (one at a time) to createDiv(). So calling data.products as it's written now is asking for the "products" property on an individual product (which doesn't exist and thus is undefined). Try updating that line to

<p>${data.product_name}</p>

I think that should fix it.

ollie_123's avatar

@ignium. You sir are a legeeeeeeend!

Thank you for this. It works perfectly 😁👍🏻

I see what you mean now. I was calling the whole object again as apposed to the product data itself.

Really appreciate your help dude.

ignium's avatar

Woohoo! Awesome! Glad we got to the bottom of it!

Previous

Please or to participate in this conversation.