how to access data from form in html using DOM code example

Example 1: js get data from form

const form = document.querySelector('form');
const data = new FormData(form);

Example 2: js get form data

document.addEventListener('submit', function (event) {

	event.preventDefault();

	fetch('https://xxx.xxx', {
		method: 'POST',
		body: new FormData(event.target),
	}).then(function (response) {
		if (response.ok) {
			return response.json();
		}
		return Promise.reject(response);
	}).then(function (data) {
		console.log(data);
	})
});