I have two arrays of strings: hrefs, thumbs. Need to combine this arrays into another array with structure like below. How to do that ? For clarity - i need to use Lightview API to call function Lightview.show(elements), where elements is result array i need to build.
HTML:
<a href="/one" class="lv" thumbnail="one.jpg">one</a>
<a href="/two" class="lv" thumbnail="two.jpg">two</a>
<a href="/three" class="lv" thumbnail="three.jpg">three</a>
Arrays:
var hrefs = $('.lv').map(function() { return $(this).attr('href'); }).get();
var thumbs = $('.lv').map(function() { return $(this).attr('thumbnail'); }).get();
The desired result array (elements):
{
{hrefs[0],
{
thumbnail: thumbs[0]
}
},
{hrefs[1],
{
thumbnail: thumbs[1]
}
},
...
}
I've started with this, but i think it is something wrong...
var e = new Array();
$.each(hrefs, function(i, value) {
e[i] = new Array();
e[i][0] = value;
e[i][1] = {thumbnail: thumbs[i]};
});
{name:value}... you can't have{{name:value}}. You could do{name1:{name2:value}}.