Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript output buffer places things in the wrong order
    primarykey
    data
    text
    <p>My regular javascript code seems to be outputting stuff to the page either incorrectly or in the wrong order, which is weird because the code is very simple (maybe 20 lines tops). My code is below. Note:</p> <ul> <li><code>pttr_data.length</code> will return 150 </li> <li><code>clean_array.length</code> will return 4. </li> <li><code>output</code> is a div object, i.e. var output = document.getElementById("results");</li> </ul> <p>I want my code to output like this: </p> <pre><code>&lt;div&gt;matcha matchb matchc matchn &lt;/div&gt; </code></pre> <p>But instead it returns:</p> <pre><code>&lt;div/&gt;matcha matchb matchc match </code></pre> <p>Here is my code, in which I placed random characters to figure out where stuff is going (you'll see the <code>;;;, |||, [[[, }}}</code> in there surrounding the divs):</p> <pre><code>var len = pttr_data.length; for (var i = 0; i &lt; len; i++) { var clean_array = pttr_data[i].match(RegExp(rexp.value, flags.value)); output.innerHTML += ";;;&lt;div&gt;|||"; var lengthy = clean_array.length; for (var j = 1; j &lt; lengthy; j++) { if( clean_array[j] ) { output.innerHTML += clean_array[j] + ' '; } else { output.innerHTML += 'NULL '; } } out.innerHTML += "[[[&lt;/div&gt;}}}\n"; } </code></pre> <p>This code returns:</p> <pre><code>;;;&lt;div&gt;|||&lt;/div&gt;matcha matchb matchc [[[}}} </code></pre> <p>Can someone explain why this occurs? Do javascript for loops operate independently (and thus finish at varying speeds), even if they are nested? This makes no sense though, why would someone design a scripting language like that?<br> How could my code output <code>&lt;div/&gt;blah</code> instead of <code>&lt;div&gt;blah&lt;/div&gt;</code> ? </p> <p>Thanks</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.
    1. This table or related slice is empty.
    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