gallimg
needs to be an array, and an array starts from index 0, not 1
var gallimg = [];
gallimg[0] = { image: "image1.jpg"};
gallimg[1] = { image: "image2.jpg"};
gallimg[2] = {image: "image3.jpg"};
DRY Solution
var images = ["image1.jpg", "image2.jpg", "image3.jpg"];
var gallimg = images.map(function (imageName) {
return {'image': imageName};
});
Result of console.log(JSON.stringify(gallimg, undefined, 4));
[
{
"image": "image1.jpg"
},
{
"image": "image2.jpg"
},
{
"image": "image3.jpg"
}
]