jquery - Javascript - Looping through an array -
overview: i'm needing update array contains image links new image links. @ same time i'm keeping uploaded images in array. problem while doing previous image links combined. example below. how change code fix array? help.
var allimages = [] var allcurrentimages = req.body.oldimages //this pulls previous image links if (allcurrentimages && allcurrentimages.length > 2){ (i=0;i<allcurrentimages.length;i++){ allimages.push(allcurrentimages[i]); } } if (filepath && filepath.length > 2){ allimages.push(filepath); }
problem
here's problem. if var allcurrentimages has 2 images in array combines them 1 item because i'm requesting body. looks when there 3 images:
images[0] = uploads/598f4cc,uploads/53eew2w images[1] = uploads/7wusjw2w
it needs this:
images[0] = uploads/598f4cc images[1] = uploads/53eew2w images[2] = uploads/7wusjw2w
so need somehow split req.body.oldimages separate parts before pushing array. (i think.) or advice appreciated!
you can split before:
var allcurrentimagestmp = req.body.oldimages var allcurrentimages = []; (i=0;i<allcurrentimagestmp .length;i++){ allcurrentimages.concat(allcurrentimagestmp[i].split(",")); } ... // code
Comments
Post a Comment