How to combine all keys and values in an object into a single string with Node.js

1 Answer

0 votes
function combineKeysAndValues(obj) {
    // Combine keys and values into a single string
    return Object.entries(obj)
        .map(([key, value]) => `${key}=${value}`)
        .join(", ");
}

const obj = {
    Key1: "Value1",
    Key2: "Value2",
    Key3: "Value3"
};

const result = combineKeysAndValues(obj);

console.log("Combined keys and values: " + result);


   
/*
run:
    
Combined keys and values: Key1=Value1, Key2=Value2, Key3=Value3
       
*/

 



answered Apr 1 by avibootz
...