A modified approach using reduce that let to change the separator sep between (key,value) tuple while checking last item:
function objectToString(obj, sep = ',') { const entries=Object.entries(obj); return entries.reduce((str, [p, val], counter) => { if (counter < entries.length - 1) { return `${str}${p}=${val}${sep}`; } else { return `${str}${p}=${val}`; } }, ''); }
function objectToString(obj, sep = ',') { const entries = Object.entries(obj); return entries.reduce((str, [p, val], counter) => { if (counter < entries.length - 1) { return `${str}${p}=${val}${sep}`; } else { return `${str}${p}=${val}`; } }, ''); } console.log( objectToString({ status_code: 200, execute_time: 0.1, ip: '1270.0.0.1' }, ','))