how to make the serialize form data in js code example

Example 1: how to serialize form data in jquery

$("button").click(function(){

  $("div").text($("form").serialize());

 });

Example 2: get serialize data javascript

// HTML
<form id="myForm" name="myForm">
  <div>
    <label for="username">Enter name:</label>
    <input type="text" id="username" name="username">
  </div>
  <button type="button" onclick="clickMe()">Click</button>
</form>

// JS
function clickMe(){
  let myForm = document.getElementById('myForm');
  let formData = new FormData(myForm);
  console.log(formData.get('username'));
}