title: jQuery-UI sortable - synchronize array (model) after update
body: <p>Let's say I have an array containing data, it would probably come from Ajax (but no need to do this here).</p>
  
  <p>With that array I generate the content of a UL element, I make that UL sortable, with jQuery-UI</p>
  
  <p>I would like to keep the order of the array synchronized with the UL, after the client sorts it anyway.</p>
  
  <p>Is there an elegant way of doing this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var locations = [
    {name: 'point 0', location: [50.8674162,4.3772933]},
    {name: 'point 1', location: [50.8135113,4.3247394]},
    {name: 'point 2', location: [50.8771732,4.3544551]},
    {name: 'point 3', location: [50.8460485,4.3664706]}
  ];
  
  function generateUl() {
    var content = '';
    for(var i in locations) {
      content += '&lt;li&gt;'+ locations[i].name +' ('+ locations[i].location.toString() +')&lt;/li&gt;';
    }
    $('#points').html(content);
  
  }
  
  $(document).ready(function() {
    generateUl();
    $('#points').sortable({
      update: function(event, ui) {
        //$('#points li').each( function(e) {
        //});
        
        // so, I would like to see this display change after every update and have the order match
        $('#display').html(JSON.stringify(locations));
      }
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"&gt;&lt;/script&gt;
  &lt;ul id="points"&gt;&lt;/ul&gt;
  &lt;div id="display"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>