Issue on Ordering - Indexing Multidimensional Array

Issue on Ordering - Indexing Multidimensional Array

Can you please take a look at This demo let me know how I can force Javascript to push the items into the array based on the items id?

<!-- begin snippet: js hide: false -->

<!-- language: lang-js -->

  1.     var theArray = [
  2.         ["A", "B", "C"],
  3.         ["D", "E"],
  4.         ["F", "G", "H", "I"],
  5.         ["J"],
  6.         ["K", "L", "M"]
  7.     ];
  8.     var res = theArray.toString();

  9.     $('#textarea').text(res);

  10.     $("input[name='m1']").change(function () {
  11.         if ($(this).is(':checked')) {
  12.             var id=$(this).attr('id');
  13.             var selected = $(this).val();        
  14.             theArray[1][id] = selected;
  15.             
  16.         } else {
  17.             var itemtoRemove = $(this).val();
  18.         theArray[1].splice($.inArray(itemtoRemove, theArray[1]),1);

  19.         }
  20.         var res = theArray.toString();
  21.     $('#textarea').text(res);
  22.         
  23.     });


  24. <!-- language: lang-html -->

  25.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  26.     <br />
  27.     <textarea id="textarea" rows="2" cols="100"></textarea>
  28.     <br />
  29.     <br />
  30.     <fieldset>
  31.         <legend>Items</legend>
  32.         <input type="checkbox" id="1" name="m1" value="mItem1" />mItem 1
  33.         <br />
  34.         <input type="checkbox" id="2" name="m1" value="mItem2" />mItem 2
  35.         <br />
  36.         <input type="checkbox" id="3" name="m1" value="mItem3" />mItem 3
  37.         <br />
  38.         <br />
  39.     </fieldset>


As you can see the example works if you un check from `mItem 3` to `mItem 3` but if you uncheck `mItem 1` first and check it again it will overwrite the mitem2 in the array (which make seance!)

Can you please let me know how i can fix this?

Thanks