Query-string encoding of a Javascript Object

前端 未结 30 2993
渐次进展
渐次进展 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:56

    Single line to convert Object into Query String in case somebody need it again

    let Objs = { a: 'obejct-a', b: 'object-b' }
    
    Object.keys(objs).map(key => key + '=' + objs[key]).join('&')
    
    // result will be a=object-a&b=object-b
    

提交回复
热议问题