I have an array of versions:
var versions = ['xs', 'sm', 'md', 'lg', 'thumbnail'];
I want to get all the image stored in this array that do not contain any of these suffixes. Here is an example of the array of images:
{
"files": [
"/public/uploads/contentitems/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0_1.png",
"/public/uploads/contentitems/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0_1_xs.png",
"/public/uploads/contentitems/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0_1_sm.png",
"/public/uploads/contentitems/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0_1_md.png",
"/public/uploads/contentitems/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0_1_lg.png",
"/public/uploads/contentitems/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0/063012A5-60BC-4A4C-AEC2-56B0D5D99EF0_1_thumbnail.png"
]
}
I only want the first item, however, I am getting all of them with my current code:
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
// perform directory code here
} else {
versions.forEach(function(version) {
if (file.indexOf(version) != -1) {
results.push(file);
}
});
}
});
versionsin the bottom code the same as the array calledversionat the top ?versions.version.forEachwill push the file unless all the vesions occur in the filename.