Deviopath › Node.js

Build a Query String

Easy · URLs

Write a function buildQuery(params) that turns an object into a query string without the leading ?, like "q=node%20js&page=2":

- encode keys and values with encodeURIComponent

- skip keys whose value is null or undefined

- an array value repeats the key: { tag: ["a", "b"] } → "tag=a&tag=b"

- no pairs → ""

Next: Base Name of a Path