简体   繁体   中英

Convert JS Object to Raw string

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\"}'

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}\\"`);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM