0

i want to convert js object to following format.

I need backward slash before every dobule quotes.

Input:

{key1: "value1", key2: "value2"}

Output:

'{key1: \"value1\", key2: \"value2\"}'
Vinay Kumar
  • 386
  • 2
  • 8

1 Answers1

0

I have no idea why you would want to do that, that would be the answer however:

for (const [key, value] of Object.entries(yourObject)) {
  console.log(`\\"${key}\\": \\"${value}\\"`);
}
Marwan
  • 388
  • 2
  • 11