Concatenating elements of two jQuery string arrays
I have two arrays of strings called old_array and new_array and I want to concatenate them together like this:
old_array = "fd.com/product1/,fd.com/product2/,fd.com/product3/"
new_array = "image1.jpg,image2.jpg,image3.jpg"
(code happens in this area)
final_array = "http://www.fd.com/product1/image1.jpg,http://www.fd.com/product2/image2.jpg,http://www.fd.com/product3/image3.jpg"
All I have seen are things that will touch the second array to the first (eg "fd.com/product1/,fd.com/product2/,d.com/product3/image1.jpg" image2. Jpg, image3. jpg "), which isn't very useful ...?
Can this be done in jQuery?
+3
source to share
3 answers
var oldArray = 'fd.com/product1/,fd.com/product2/,fd.com/product3/'.split(','),
newArray = 'image1.jpg,image2.jpg,image3.jpg'.split(',');
var finalArray = oldArray.map(function(e, i) {
return 'http://' + e + newArray[i];
});
document.write(finalArray);
+4
source to share