0

I get data via ajax. In results data.items I have:

image1, image2, ..., imageN 

each represents an image name like 109298109991.jpg

I try to write a function

$.each(images, function(i,item){

  var image_n = 'data.items.image' + (i+1); 

  console.log(image_n.value);

  images_restruct.push({ 
  href: '/images/flowercatalog/'+ image_n
  title: 'Image' + i
 });
});

But image_n is interpreted as string data.items.image1, data.items.image2 ... data.items.imageN, not as 01010101001.jpg ... 00001112121.jpg

5

1 Answer 1

3
$.each(data.items, function(i, item){
    images_restruct.push({ 
        href: '/images/flowercatalog/'+ data.items[item],
        title: 'Image' + i
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.