← All Exercises
Convert FormData Entries into a Plain Object
basicjavascript
Background
FormData supports repeated names such as checkboxes and multi-selects; naive Object.fromEntries silently keeps only the last value.
Problem
Write serializeEntries(entries) that converts FormData-style name and value pairs into a plain object, preserving order for repeated names and ignoring blank values.
Input
A JSON string with an entries array of name and value pairs.
Output
A JSON string of the serialized object.
Sample tests
Sample 1
Input: {"entries":[["email","[email protected]"],["tag","css"],["tag","html"],["notes"," "]]}Expected: {"email":"[email protected]","tag":["css","html"]}Sample 2
Input: {"entries":[["subscribe","on"],["subscribe",""],["name"," Ada "]]}Expected: {"subscribe":"on","name":"Ada"}Sample 3
Input: {"entries":[[" ","x"],["empty",""]]}Expected: {}Your solution
Learning objective
Serialize FormData semantics into a plain object while preserving repeated fields and ignoring empty submissions.