Query-string encoding of a Javascript Object

前端 未结 30 2994
渐次进展
渐次进展 2020-11-22 00:23

Do you know a fast and simple way to encode a Javascript Object into a string that I can pass via a GET Request?

No jQuery, no

30条回答
  •  时光取名叫无心
    2020-11-22 00:53

    Well, everyone seems to put his one-liner here so here goes mine:

    const encoded = Object.entries(obj).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join("&");
    

提交回复
热议问题