check the checkbox if name and value match with the input checkbox field

var url = 'http://127.0.0.1:8000/search/?name=san&language=1&cast=1&language=2&cast=3';
existingUrl(url.substring(url.indexOf('?') + 1));

function existingUrl(query) {
  var urlparts = query.split('&');
  $('.language, .cast').each(function() {
    var hasValue = urlparts.indexOf($(this).prop('name') + '=' + $(this).val());
    this.checked = (hasValue != -1);
  });
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form method="get">


  <input type="text" name="name" id="name" hidden> language
  <input type="checkbox" name="language" class="language" id="1" value="1"> cast
  <input type="checkbox" name="cast" class="cast" id="2" value="1"> language
  <input type="checkbox" name="language" class="language" id="3" value="2"> cast
  <input type="checkbox" name="cast" class="cast" id="4" value="3">
  <input type="submit" value="submit">
</form>