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 SinghPosted Feb 23, 2021, 7:42 PM
BD OnePosted Feb 23, 2021, 7:32 PM
Sachin SinghPosted Feb 23, 2021, 6:53 PM