I have the following code:
const formSubmit = (e) => {
console.log("form submitted")
e.preventDefault()
const formData = new FormData(e.target)
console.log(formData.get('firstName'))
console.log(formData.get('lastName'))
}
document.querySelector('form').addEventListener('submit', formSubmit)
<form>
<input name="firstName" />
<input name="lastName" />
<button type="submit"> Create User </button>
</form>
I want to be able to access firstName and lastName as simple as:
console.log(formData.firstName)
console.log(formData.lastName)
However, I can't, because new FormData() returns something (I'm not sure which data type it returns, a map?).
How to convert this retuned value to an object, so I can access its properties as simple as described above?