how to use splice to remove course from jquery code

how to use splice to remove course from jquery code

in the view model i need  to remove the course from course list using splice by javascript
i need to delete index without any problem so that i use splice
how to do that if possible

  1. @model WebCourse.Models.Cusomemp2
  2. @{
  3.     Layout = null;
  4. }

  5. <!DOCTYPE html>

  6. <html>
  7. <head>
  8.     <meta name="viewport" content="width=device-width" />
  9.     <title>Edit</title>
  10.     <script src="~/scripts/jquery-1.10.2.js"></script>
  11.     <script>
  12.         $(function () {
  13.           
  14.             var index = 0;
  15.             $("#CourseId").change(function () {

  16.                 var id = $(this).val();
  17.                 var txt = $("#CourseId option:selected").text();
  18.                 $("#tb").append("<tr><td><input type = 'hidden' name='empcourses[" + index + "].CourseId' value='" + id + "'/></td><td>" + txt + "</td><td><input type='button' value='remove' class='r'</td></tr>")

  19.                 index++;
  20.             });
  21.             $("#tb").on("click", ".r", function () {
  22.                 $(this).parent().parent().hide();
  23.                 $(this).parent().prev().prev().find("input").val("0");
  24.             });
  25.             $.ajax({
  26.                 url: "/Employee/getcoursesbyempid",
  27.                 data:{x:$("#hid").val()},
  28.                 success: function (res) {
  29.                     $.each(res, function (i, e) {
  30.                         $("#tb").append("<tr><td><input type = 'hidden' name='empcourses[" + index + "].CourseId' value='" + e.Id + "'/></td><td>" + e.CourseName + "</td><td><input type='button' value='remove' class='r'</td></tr>")

  31.                         index++;
  32.                     });
  33.                 }
  34.                 
  35.             })
  36.         });
  37.     </script>
  38. </head>
  39. <body>
  40.     <div>
  41.         @using (Html.BeginForm())
  42.         {
  43.             <div>
  44.                 <input type="hidden" value="@ViewBag.hid" id="hid" />
  45.                 Courses:@Html.DropDownList("CourseId")
  46.                 <br />
  47.                 <table id="tb"></table>
  48.                 <input type="submit" value="save" />

  49.             </div>

  50.         }
  51.     </div>
  52. </body>
  53. </html>
the code above using for remove course from list using jquery as image
i need to replace code above for remove by using splice
because i need actually delete index by javascript