Overview: I'm needing to update an array that contains image links with any new image links. At the same time I'm keeping all previously uploaded images in the array. My problem is that while doing this the previous image links get combined. Example below. How would I change my code to fix the array? Thanks for any help.
var allimages = []
var allCurrentImages = req.body.oldimages
//this pulls all the previous image links
if (allCurrentImages && allCurrentImages.length > 2){
for (i=0;i<allCurrentImages.length;i++){
allimages.push(allCurrentImages[i]);
}
}
if (filepath && filepath.length > 2){
allimages.push(filepath);
}
PROBLEM
Here's the problem. If var allCurrentImages has two images in it the array combines them into one item because I'm requesting the body. It looks like this when there are 3 images:
images[0] = uploads/598f4cc,uploads/53eew2w
images[1] = uploads/7wusjw2w
It needs to look like this:
images[0] = uploads/598f4cc
images[1] = uploads/53eew2w
images[2] = uploads/7wusjw2w
So I need to somehow split the req.body.oldimages into separate parts before pushing it to the array. (I think.) Any help or advice is greatly appreciated!
allCurrentImagesis an array, and it has two images, the condition never runs, as the array would need a length of 3 or more before the condition runs ?uploads/598f4cc,uploads/53eew2was a single item when iterating, was ifreq.body.oldimageswas in fact an array, otherwise it would be like this -> jsfiddle.net/x11dxdzj/2