Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing Javascript Array
    primarykey
    data
    text
    <p>I have an array as a attribute on a link.</p> <p>Here is the array</p> <pre><code>images="["one.jpg","two.jpg"]" </code></pre> <p>How would I parse through this array and have it read back to me one.jpg,two.jpg?</p> <p>This is what I am doing now and it is giving me an error back. I don't believe json parsing is whats needed here.</p> <pre><code>var imgs = $("#"+number).attr("images"); var imgList = jQuery.parseJSON(imgs); </code></pre> <p>EDIT: ACTUAL CODE</p> <pre><code>var number = $(this).attr("data-id"); var url = $("#"+number).attr("url"); $(".portfolio-url").html("&lt;h3 class='pacifico'&gt;url&lt;/h3&gt;&lt;p&gt;&lt;a href='http://"+url+"' target='_blank'&gt;"+url+"&lt;/a&gt;&lt;/p&gt;"); var cli = $("#"+number).attr("client"); $(".portfolio-client").html("&lt;h3 class='pacifico'&gt;client&lt;/h3&gt;&lt;p&gt;"+cli+"&lt;/p&gt;"); var pgs = $("#"+number).attr("pages"); pgs = pgs.replace(/\[/g,""); pgs = pgs.replace(/\]/g,""); pgs = pgs.replace(/\"/g,""); var pages = new Array(); pages = pgs.split(","); var img = $("#"+number).attr("images"); img = img.replace(/\{/g,""); img = img.replace(/\}/g,""); img = img.replace(/\"/g,""); var images = new Array(); images = img.split(","); var portSkills = "&lt;h3 class='pacifico'&gt;skills&lt;/h2&gt;"; portSkills += "&lt;p&gt;"; for (i=0;i&lt;pages.length;i++) { if (pages[i] != "Clients") { var finalPage = ""; for (j=0;j&lt;pages[i].length;j++) { var ch = pages[i].charAt(j); if (ch == ch.toUpperCase()) { finalPage += " "; } finalPage += pages[i].charAt(j); } portSkills += finalPage+"&lt;br /&gt;"; } } portSkills += "&lt;/p&gt;"; $(".portfolio-skills").html(portSkills); var imgs = $("#"+number).attr("images"); var imgList = jQuery.parseJSON(imgs); </code></pre> <p>Basically, its looping through parameters</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload