hey community,
I am making a pdf with information from a website. My problem is the image. If there is an image it works with the codes:
- const first_picture_url: string = product.pictures[0].url;
- const other_picture_urls: string[] = product.pictures.filter(
- (_: { url }, index: number) => index > 0).map((picture: { url }) => picture.url);
TypeError: Cannot read property 'url' of undefined.
i found out i could prevent this with
- if(product.pictures.length<1)
My try:
- if(product.pictures.length>0){
- const first_picture_url: string = product.pictures[0].url;
- const other_picture_urls: string[] = product.pictures.filter(
- (_: { url }, index: number) => index > 0).map((picture: { url }) => picture.url);
- }
- else
- {
- const first_picture_url: string = String(product.airCoolingIntegrated);
- }
i just want these lines not be initiated if the length of the attribute is 0. (so no picture existing).
Can anyone help me with that maybe?
Greetings

Sachin SinghRank #66 · 26.2K reputationPosted Feb 23, 2021, 2:42 PM EST
Sachin SinghRank #66 · 26.2K reputationPosted Feb 23, 2021, 1:53 PM EST
BD One7 reputationPosted Feb 23, 2021, 2:32 PM EST