forming a 2D array in jquery -
i'm trying create 2d array consisting of url , text in "a href" element.
i think got working, not sure if correct structure 2d array. output in console, looks 1d array.
i need [link url, linktext]
example: [http://www.yahoo.com, yahoo!]
could please take , see if 2d array?
thanks
here jsfiddle:
var linkarray = []; $('[class=hrefurl]').each(function (i) { var text = ($(this).text()); var url = ($(this).attr('href')); linkarray.push(url, text); }); (var = 0; < linkarray.length; i++) { console.log(linkarray[i]); }
change
linkarray.push(url, text);
to
linkarray.push([url, text]);
or use objects instead of arrays inner element bit more structured:
linkarray.push({url: url, text: text});
Comments
Post a Comment