I have checkbox function but I have problem in getting the value of the checkbox after clicking the submit button. I have done the function and seems like I can't figure out on how to fix this problem.
let fruit_temp = [];
$(document).ready(function() {
  $('input[name="fruitGroup"]').change(function() {
    fruit_temp = [];
    $('input[name="fruitGroup"]:checked').each(function() {
      fruit_temp.push($(this).val());
    });
  });
});
const getFruitType = () => {
  axios.get(`${url}FruitList`)
    .then(function(response) {
      if (response.data.status == 'success') {
        response.data.result.map((e) => {
          $('#fruitlist').append(`<li><label class="checkbox"><input type="checkbox" name="fruitGroup" value="${e.id}" > ${e.name}</label></li>`);
        });
      }
    });
}
const submit = () => {
  let formData = new FormData();
  //more formData
  formData.append('Fruit', fruit_temp);
  for (var pair of formData.entries()) {
    console.log(pair[0] + ', ' + pair[1]);
  }
}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-lg-12 mb-30">
  <label><b>Choose Multiple Fruit</b></label><br>
  <div class="form-group">
    <ul id="fruitlist"></ul>
  </div>
</div>
<button onclick="submit()">Submit</button>