Plain Javascript Equivalent of jQuery.param()

后端 未结 7 1261
小蘑菇
小蘑菇 2021-02-07 11:04

jQuery.param() takes an array of key-value pairs, and turns it into a string you can use as a query string in HTML requests. For example,

a = {
      userid:1,
         


        
7条回答
  •  悲&欢浪女
    2021-02-07 11:41

    export function param( params ) {
        const p = new URLSearchParams;
        for( const [ key, value ] of Object.entries( params ) ) {
            p.set( key, String( value ) );
        }
        return p.toString();
    }
    

提交回复
热议问题