yes, there is. You would simply check per image if(image). If this returns true you build a new array with .push (see W3schools for arrays and Push) and when you cycled tru all of them, you hand the new array to the slides.
I have written the following code the pictures are still “pushed” even if the field is empty, something with the if condition? I have tried !== null and !== 0 both not working
$w.onReady(function () {
$w('#dynamicDataset').onReady(() => {
let item = $w('#dynamicDataset').getCurrentItem();
let itemsForGallery = [];
for (let i = 1; i < 6; i++) {
if (item[`image${i}`] !== '') {
itemsForGallery.push({src: item[`image${i}`] });
}
}
$w("#gallery1").items = itemsForGallery;
});