Following is the code which is working fine for me, the only problem here I can see that I need to call slice(0, -1)
on my string to remove &
from the last. Let me know if there is a better and efficient way of writing this or this is also acceptable.
Thanks in advance.
Code -
const object1 = {
a: 'somestring',
b: 42,
c: '',
d: "test1",
e: null,
f: 'test2'
};
let str = '';
for (const [key, value] of Object.entries(object1)) {
str += `${key}=${value}&`
}
const paramStr = str.slice(0, -1);
console.log(paramStr);