Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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"}'
question from:https://stackoverflow.com/questions/65935485/convert-js-object-to-raw-string

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
162 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...