I'm trying make buttons to append images to HTML from array. Why the first snippet doesn't work?
First snippet with array doesn't work
const fs = require('fs');
const dir = fs.readdirSync('/Files/Изображение').filter(files => files.endsWith('.png'))
let imag = dir[0];
function createImgBlock() {
const imgBlocks = document.createElement('img');
imgBlocks.src = '/Files/Изображение/' + dir[0];
document.body.append(imgBlocks);
}
Second snippet only with the name of image is work
const fs = require('fs');
const dir = fs.readdirSync('/Files/Изображение').filter(files => files.endsWith('.png'))
let imag = dir[0];
function createImgBlock() {
const imgBlocks = document.createElement('img');
imgBlocks.src = '/Files/Изображение/' + '1407916_900_600.png';
document.body.append(imgBlocks);
}