JS Built-ins
URLSearchParamsbeginner

URLSearchParams#keys() β€” iterate over keys

πŸ“– Usage Example
const p = new URLSearchParams('a=1&b=2')
for (const [k, v] of p) {
  console.log(k, v)
}  // a 1, then b 2

URLSearchParams is iterable; each entry yields a [key, value] pair.

URLSearchParams#keys()

params.keys() returns an iterator of all key names. Use Array.from() to convert to an array.

Challenge: Get all keys as an array.

πŸ’‘ Hints (1)
  • β€’ Use Array.from() or spread [...params.keys()] to convert the iterator