'How to display the image of instead of empty array

const customImage = tmpl.customImage ? tmpl.customImage.map(c => c.url) : "https://yourl img here";

here tmpl.customImage is getting empty array[] so i want to display a default image instead of empty. But it is not fetching to default image it is showing empty...

Please help me thanks in advance



Solution 1:[1]

How about checking it length?

const customImage = tmpl.customImage.length ? tmpl.customImage.map(c => c.url) : "https://yourl img here";

Solution 2:[2]

use instead of that: const customImage = tmpl.customImage.length ? tmpl.customImage.map(c => c.url) : "https://yourl img here";

Solution 3:[3]

give your image url link in that array make that variable and use res.render to render your file

Solution 4:[4]

Is tmpl.customImage already an array, then why assign an array to customImage ?

You can handle the empty array here:

tmpl.customImage.push({"url":"https://yourimghere"}); // add to the end
const customImage = tmpl.customImage.shift(); // take from the top

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andret2344
Solution 2 MD OZAIR QAYAM
Solution 3 Urval Panchal
Solution 4 mplungjan