Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
Why does Object.fromEntries(formData) work
  1. I've got a form.
  2. I listen when user submit it.
  3. I make a new instance of the FormData class.
  <form>
    <input type="text" name="username">
    <input type="submit">
  </form>

  const form = document.querySelector('form');
  form.addEventListener('submit', (e) => {
    e.preventDefault();
    const formData = new FormData(form);
  });

I know that formData.entries() will return an iterable, so i can use a for of loop to get the pairs... What i don't get is why this actually works:

const pairValues = Object.fromEntries(formData);

formData is an instance of a class that HAS multiple methods. Is not an iterable itself.

Does Object.fromEntries looks for an iterator by default?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is because a FormData object has a Symbol.iterator method, which makes it iterable.

You can check and see that:

formData[Symbol.iterator] === formData.entries

They are the same function.

Now Object.fromEntries(form) accepts an iterable, as also mdn documents:

Parameters

iterable

An iterable such as Array or Map or other objects implementing the iterable protocol.

So Object.fromEntries will invoke formData[Symbol.iterator], which is the same as calling formData.entries.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!