title: Order <li> elements by id from array
body: <p>I've used Jquery's sortable() to create an array that is saved to a database. The array contains the li id's of all li items in the ul. It is based on a drag n drop function.</p>
  <pre><code>&lt;script&gt;
        $(document).ready(function () {
            $('ul').sortable({
                axis: 'y',
                stop: function (event, ui) {
                    let data = $(this).sortable('toArray');
                    $('span').text(data);
                    $(&quot;#HiddenSortOrder&quot;).val(JSON.stringify(data))
                    console.log(data);
                }
            });
        });
  &lt;/script&gt;
  </code></pre>
  <p>The array it produces looks like this:</p>
  <pre><code>[&quot;13&quot;,&quot;14&quot;,&quot;16&quot;,&quot;15&quot;,&quot;&quot;,&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;10&quot;,&quot;11&quot;,&quot;12&quot;,&quot;17&quot;,&quot;18&quot;,&quot;19&quot;,&quot;20&quot;,&quot;21&quot;,&quot;22&quot;,&quot;23&quot;,&quot;24&quot;,&quot;25&quot;,&quot;26&quot;,&quot;27&quot;,&quot;46&quot;,&quot;52&quot;,&quot;&quot;]
  </code></pre>
  <p>I am trying to use this array to set the order of a list on another page. The li items look like this:</p>
  <pre><code>&lt;li class=&quot;ui-state-default&quot; id=&quot;1&quot;&gt;&lt;a href=&quot;linkOfSomething.php&quot;&gt;nameOfSomething&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  <p>So far I've found/come up with:</p>
  <pre><code>$data[] = $sortOrderArray;
      &lt;script&gt;
          var sorted = $data[];
          sorted.forEach(function(id) {
              $(&quot;#&quot; + id).appendTo(&quot;#sortable&quot;)
          })
      &lt;/script&gt;
  </code></pre>
  <p>Or something like:</p>
  <pre><code>array.forEach(function(item) {
    var li = document.createElement(&quot;li&quot;);
    var text = document.createTextNode(item);
    li.appendChild(text);
    document.getElementById(&quot;myUl&quot;).appendChild(li);
  });
  </code></pre>
  <p>I am however very unsure how to properly implement this. And if I am on the right track to begin with. Any suggestions?</p>