इसके लिए आप पार्स () के साथ रिप्लेस () का इस्तेमाल कर सकते हैं। निम्नलिखित कोड है -
उदाहरण
var studentDetails = `"{""name"": ""John"",""subjectName"":
""Introduction To JavaScript""}"`;
console.log("The actual object=");
console.log(studentDetails);
var removeFirstAndLast = studentDetails.substring(1,studentDetails.length-1)
var removeDoubleQuotes = removeFirstAndLast.replace(/""/gi, `"`)
console.log(removeDoubleQuotes)
var output = JSON.parse(removeDoubleQuotes);
console.log(output); उपरोक्त प्रोग्राम को चलाने के लिए, आपको निम्न कमांड का उपयोग करने की आवश्यकता है -
node fileName.js.
यहाँ, मेरी फ़ाइल का नाम है demo103.js.
आउटपुट
यह निम्नलिखित आउटपुट देगा -
PS C:\Users\Amit\JavaScript-code> node demo103.js
The actual object=
"{""name"": ""John"",""subjectName"": ""Introduction To JavaScript""}"
{"name": "John","subjectName": "Introduction To JavaScript"}
{ name: 'John', subjectName: 'Introduction To JavaScript' }