marb
marb

Reputation: 53

Javascript, how to link array elements to different urls

Hi this is the part of my code. I need to link each image in the array to different urls. Is this even possible to do it from inside, like dataArrClothes.push(["imagename.jpg","<a href="someurl"></a> "Description"]); Any help is greatly appreciated.

var dataArrClothes = new Array();
dataArrClothes.push(["imagename.jpg", "Description"]);
dataArrClothes.push(["imagename.jpg", "Description"]);

Upvotes: 0

Views: 152

Answers (2)

Mike Christensen
Mike Christensen

Reputation: 91598

You can use an object literal, such as:

dataArrClothes.push(
   {ImageUrl: 'imagename.jpg',
    Description: 'Your description here'
   });

Upvotes: 0

jondavidjohn
jondavidjohn

Reputation: 62392

You probably want to use an array of objects instead of an array of arrays..

var dataArrClothes = [];

dataArrClothes.push({ img_src: "imagename.jpg", description: "Description"});

dataArrClothes.push({ img_src: "imagename.jpg", description: "Description"});

This would give you the following...

dataArrClothes[0].img_src; // "imagename.jpg"

dataArrClothes[0].description: // "Description"

You then have array of objects with img_src and description properties.

Upvotes: 2

Related Questions